note 61120 added to function.utf8-decode
| From: | 2ge at NO2geSPAM dot us | Date: | Thu, 26 Jan 2006 09:00:22 +0000 |
| Subject: | note 61120 added to function.utf8-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102465@lists.php.net to get a copy of this message | ||
Hello all,
I like to use COOL (nice) URIs, example: http://server/fucking-amal
I'm using UTF8 as input, so I have to write a function UTF8toASCII to have nice URI. Here is
what I come with:
<?php
function urlize($url) {
$search = array('/[^a-z0-9]/', '/--+/', '/^-+/', '/-+$/' );
$replace = array( '-', '-', '', '');
return preg_replace($search, $replace, utf2ascii($url));
}
function utf2ascii($string) {
$iso88591 = "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7";
$iso88591 .= "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF";
$iso88591 .= "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7";
$iso88591 .= "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF";
$ascii = "aaaaaaaceeeeiiiidnooooooouuuuyyy";
return strtr(mb_strtolower(utf8_decode($string), 'ISO-8859-1'),$iso88591,$ascii);
}
echo urlize("Fucking ämäl");
?>
I hope this helps someone.
----
Server IP: 62.65.181.66
Probable Submitter: 212.89.233.179
----
Manual Page -- http://www.php.net/manual/en/function.utf8-decode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61120
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61120&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61120&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61120&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61120&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61120&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61120&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61120&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61120&report=yes
Search -- http://master.php.net/manage/user-notes.php