Convert Foreign Characters in PHP

I couldn't find a built in function to convert foreign characters, so I constructed the following, which seems to be working well. However, I'm not sure how it will hold up on other machines with other charsets… But hopefully it works for you and saves some time.

1.   function convert_foreign_characters($string) {
2.   	$find = "àèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖܟåÅøØ";
3.   	$replace = "aeiouAEIOUaeiouyAEIOUYaeiouAEIOUanoANOaeiouyAEIOUYaAoO";
4.   	$output = strtr($string,$find,$replace);
5.   	return $output;
6.   }

This Character Entity Reference Chart is really helpful too.

Leave a Comment

Name and email are required. Your email will not be published.

This post was first published on November 25th, 2009 and last updated on March 13th, 2014 by Robert James Reese in PHP. Before using any of the code or other content in this post, you must read and agree to our Terms & Conditions.