note 110524 added to function.strtr
| From: | Tedy | Date: | Thu, 01 Nov 2012 20:43:52 +0000 |
| Subject: | note 110524 added to function.strtr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191628@lists.php.net to get a copy of this message | ||
Since strtr() is twice faster than strlwr I decided to write my own lowering function which also
handles UTF-8 characters.
<?php
function strlwr($string, $utf = 1)
{
$latin_letters = array('Ä' => 'a',
'Ã' => 'a',
'Ã' => 'i',
'È' => 's',
'Å' => 's',
'È' => 't',
'Å¢' => 't');
$utf_letters = array('Ä' => 'Ä',
'Ã' => 'â',
'Ã' => 'î',
'È' => 'È',
'Å' => 'Å',
'È' => 'È',
'Å¢' => 'Å£');
$letters = array('A' => 'a',
'B' => 'b',
'C' => 'c',
'D' => 'd',
'E' => 'e',
'F' => 'f',
'G' => 'g',
'H' => 'h',
'I' => 'i',
'J' => 'j',
'K' => 'k',
'L' => 'l',
'M' => 'm',
'N' => 'n',
'O' => 'o',
'P' => 'p',
'Q' => 'q',
'R' => 'r',
'S' => 's',
'T' => 't',
'U' => 'u',
'V' => 'v',
'W' => 'w',
'X' => 'x',
'Y' => 'y',
'Z' => 'z');
return ($utf == 1) ? strtr($string, array_merge($utf_letters, $letters)) : strtr($string,
array_merge($latin_letters, $letters));
}
?>
This allows you to lower every character (even UTF-8 ones) if you don't set the second
parameter, or just lower the UTF-8 ones into their specific latin characters (used when making
friendly-urls for example).
I used romanian characters but, of course, you can add your own local characters.
Feel free to use/modify this function as you wish. Hope it helps.
----
Server IP: 69.147.83.199
Probable Submitter: 86.122.225.45
----
Manual Page -- http://www.php.net/manual/en/function.strtr.php
Edit -- https://master.php.net/note/edit/110524
Del: integrated -- https://master.php.net/note/delete/110524/integrated
Del: useless -- https://master.php.net/note/delete/110524/useless
Del: bad code -- https://master.php.net/note/delete/110524/bad+code
Del: spam -- https://master.php.net/note/delete/110524/spam
Del: non-english -- https://master.php.net/note/delete/110524/non-english
Del: in docs -- https://master.php.net/note/delete/110524/in+docs
Del: other reasons-- https://master.php.net/note/delete/110524
Reject -- https://master.php.net/note/reject/110524
Search -- https://master.php.net/manage/user-notes.php