Possible Duplicate:
PHP: Replace umlauts with closest 7-bit ASCII equivalent in an UTF-8 string
I need to change strings that have accents E.G: Casá to become Casa. Is there an easy way to do it with PHP? Thanks
Possible Duplicate:
PHP: Replace umlauts with closest 7-bit ASCII equivalent in an UTF-8 string
I need to change strings that have accents E.G: Casá to become Casa. Is there an easy way to do it with PHP? Thanks
$text = iconv('UTF-8', 'US-ASCII//TRANSLIT', $text);
if iconv doesn't work well for your purposes, strtr will replace characters with replacement characters that you assign.
http://php.net/manual/en/function.strtr.php
<?php
//In this form, strtr() does byte-by-byte translation
//Therefore, we are assuming a single-byte encoding here:
$addr = strtr($addr, "äåö", "aao");
?>
some user example...
$GLOBALS['normalizeChars'] = array(
'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'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', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f'
);
return strtr($toClean, $GLOBALS['normalizeChars']);
"á" and "a" are different letters; one is not simply "a with an accent". You need to define the mapping that you want between characters. Then perhaps make an array of suitable character replacements, and apply them in a loop over the input string.
you can use htmlentities()
and preg_replace()
(to select the second character).
Example:
echo preg_replace(
'/&([a-zA-Z])(uml|acute|grave|circ|tilde|cedil|ring);/',
'$1',
htmlentities("Hélicoïdal"));