note 119296 added to function.strtolower
| From: | DanielKlein | Date: | Sat, 07 May 2016 10:33:04 +0000 |
| Subject: | note 119296 added to function.strtolower | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205437@lists.php.net to get a copy of this message | ||
When the locale is set to "utf8" or "C" I can't get strtolower() to convert
accented characters encoded as UTF-8, so here is my workaround.
<?php
function tolower($string) {
if ($old_locale = setlocale(LC_CTYPE, 0)) {
// 'fr_FR.ISO-8859-1' for *nix, 'French_France.1252' fallback for Windows
if ($newlocale = setlocale(LC_CTYPE, 'fr_FR.ISO-8859-1',
'French_France.1252')) {
preg_match('/\.(?<encoding>.+)$/', $newlocale, $match);
$string = utf8_encode(strtolower(utf8_decode($string)));
}
setlocale(LC_CTYPE, $old_locale);
}
return $string;
}
print(tolower('DÃJÃ-VU')); // prints déjà -vu
?>
Change the language-country codes if you want some language other than French.
----
Server IP: 72.52.91.14
Probable Submitter: 211.30.51.139
----
Manual Page -- http://php.net/manual/en/function.strtolower.php
Edit -- https://master.php.net/note/edit/119296
Del: integrated -- https://master.php.net/note/delete/119296/integrated
Del: useless -- https://master.php.net/note/delete/119296/useless
Del: bad code -- https://master.php.net/note/delete/119296/bad+code
Del: spam -- https://master.php.net/note/delete/119296/spam
Del: non-english -- https://master.php.net/note/delete/119296/non-english
Del: in docs -- https://master.php.net/note/delete/119296/in+docs
Del: other reasons-- https://master.php.net/note/delete/119296
Reject -- https://master.php.net/note/reject/119296
Search -- https://master.php.net/manage/user-notes.php