php - Remove alt-codes from string -
is there possibility replace alt-code-characters "" in php?
example input: hell©ó
output should be: hello
i've tried preg_replace("/[^a-za-z]+/i", "", $string);
edit:
the problem have iconv string before because need letters "á" replaced alphanumeric ones, should not deleted because need compare string later. preg_replace change "ke©álo" "kelo". need put out "kealo".
this can achieved using 2 seperate functions.
strtr()
first, preg_replace()
following strtr()
in order while using present preg_replace("/[^a-za-z]+/i", "", $string);
code.
sidenote: can later add array if needed. 'é'=>'e'
example.
$string = "ke©álo"; // borrowed http://stackoverflow.com/a/3373364/ $unwanted_array = array( 'Š'=>'s', 'š'=>'s', 'Ž'=>'z', 'ž'=>'z', 'À'=>'a', 'Á'=>'a', 'Â'=>'a', 'Ã'=>'a', 'Ä'=>'a', 'Å'=>'a', 'Æ'=>'a', 'Ç'=>'c', 'È'=>'e', 'É'=>'e', 'Ê'=>'e', 'Ë'=>'e', 'Ì'=>'i', 'Í'=>'i', 'Î'=>'i', 'Ï'=>'i', 'Ñ'=>'n', 'Ò'=>'o', 'Ó'=>'o', 'Ô'=>'o', 'Õ'=>'o', 'Ö'=>'o', 'Ø'=>'o', 'Ù'=>'u', 'Ú'=>'u', 'Û'=>'u', 'Ü'=>'u', 'Ý'=>'y', 'Þ'=>'b', 'ß'=>'ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' ); $string = strtr( $string, $unwanted_array ); $newstring = preg_replace("/[^a-za-z]+/i", "", $string); echo $newstring; // echo'd kealo
"i need put out "kealo"."
Comments
Post a Comment