CodeIgniter Forums
url_title bug - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: url_title bug (/showthread.php?tid=3514)



url_title bug - El Forum - 10-07-2007

[eluser]yello[/eluser]
The url_title() function does not work with characters with accents

Trois Riviéres -> trois-rivires

It removes the character instead of replacing "é" with "e"... the same thing happens with other characters with accents.


url_title bug - El Forum - 10-07-2007

[eluser]Derek Allard[/eluser]
é would be illegal in a url, so that's why its stripped out. The problem with replacing it with "e", is that "e" is not the same thing as "é". For french characters, its a pretty reasonable 1 to 1 map, but what would the url_title function do with other illegal characters, such as say... "£"?

Its tricky. Perhaps an array of "if you see this, make it this"? I'm not sure. How would you suggest CI handle chars that don't nicely map to legal URL characters?


url_title bug - El Forum - 10-07-2007

[eluser]marcoss[/eluser]
[quote author="yello" date="1191796655"]The url_title() function does not work with characters with accents

Trois Riviéres -> trois-rivires

It removes the character instead of replacing "é" with "e"... the same thing happens with other characters with accents.[/quote]

This is what i use,
Code:
function replace_accents($str) {
        $str = htmlentities($str, ENT_COMPAT, "UTF-8");
        $str = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',$str);
        return html_entity_decode($str);
    }