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.

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

This Character Entity Reference Chart is really helpful too.



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 of use.