JuanDBB Posted January 7, 2010 Share Posted January 7, 2010 Hello, Sorry if this is too simple, but I'm becoming crazy with this. I want to change special characters like á, é, é, ó ú and ñ for a,e,i,o,u, n I'm doing this: function friendlyName($name) { $name = strtolower($name); $name = str_replace(" ", "", $name); $find = array('á', 'é', 'í', 'ó', 'ú', 'ñ'); $repl = array('a', 'e', 'i', 'o', 'u', 'n'); $name = str_replace ($find, $repl, $name); return $name; } BUT this doesn't work. It doesn't replace anything. If the name is "La Coruña" it returns "lacoruña" or if it's "León" it returns "león" Anybody has an idea about what may be happening? Thanks a lot in advance! Quote Link to comment https://forums.phpfreaks.com/topic/187647-need-help-with-str_replace/ Share on other sites More sharing options...
Psycho Posted January 7, 2010 Share Posted January 7, 2010 Odd. The function works for me. Must be something to do with the character encoding for the page. However, here is a more complete list of character replacements. (found it here: http://www.randomsequence.com/articles/removing-accented-utf-8-characters-with-php/) <?php function friendlyName($name) { $find = explode(","," ,ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u"); $repl = explode(",",",c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u"); return str_replace ($find, $repl, strtolower($name)); } echo friendlyName("La Coruña"); //Output: lacoruna echo friendlyName("León"); //Output: leon ?> Quote Link to comment https://forums.phpfreaks.com/topic/187647-need-help-with-str_replace/#findComment-990678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.