note 89915 added to function.mb-detect-encoding
| From: | matthijsatischendotnl at osu1 dot php dot net | Date: | Sat, 28 Mar 2009 18:33:21 +0000 |
| Subject: | note 89915 added to function.mb-detect-encoding | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152555@lists.php.net to get a copy of this message | ||
I seriously underestimated the importance of setlocale...
<?php
$strings = array(
"mais coisas a pensar sobre diário ou dois!",
"plus de choses à penser à journalier ou à deux !",
"¡más cosas a pensar en diario o dos!",
"più cose da pensare circa giornaliere o due!",
"flere ting å tenke på hver dag eller to!",
"Dalšà vÄcÃ, pÅemýšlet o každý den nebo dva!",
"mehr über Spaà spät schönen",
"më vonë gjatë fun bukur",
"több mint szórakozás késŠcsodálatos kenyér"
);
$convert = array();
setlocale(LC_CTYPE, 'de_DE.UTF-8');
foreach( $strings as $string )
$convert[] = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string);
?>
Produces the following:
Array
(
[0] => mais coisas a pensar sobre diario ou dois!
[1] => plus de choses a penser a journalier ou a deux !
[2] => ?mas cosas a pensar en diario o dos!
[3] => piu cose da pensare circa giornaliere o due!
[4] => flere ting aa tenke paa hver dag eller to!
[5] => Dalsi veci, premyslet o kazdy den nebo dva!
[6] => mehr ueber Spass spaet schoenen
[7] => me vone gjate fun bukur
[8] => toebb mint szorakozas keso csodalatos kenyer
)
whereas
<?php
$convert = array();
setlocale(LC_CTYPE, 'nl_NL.UTF-8');
foreach( $strings as $string )
$convert[] = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string);
?>
produces:
Array
(
[0] => mais coisas a pensar sobre di?rio ou dois!
[1] => plus de choses ? penser ? journalier ou ? deux !
[2] => ?m?s cosas a pensar en diario o dos!
[3] => pi? cose da pensare circa giornaliere o due!
[4] => flere ting ? tenke p? hver dag eller to!
[5] => Dal?? v?c?, p?em??let o ka?d? den nebo dva!
[6] => mehr ?ber Spass sp?t sch?nen
[7] => m? von? gjat? fun bukur
[8] => t?bb mint sz?rakoz?s k?s? csod?latos keny?r
)
This might be of interest when trying to convert utf-8 strings into ASCII suitable for URL's,
and such. this was never obvious for me since I've used locales for us and nl.
----
Server IP: 83.137.20.135
Probable Submitter: 212.182.187.28
----
Manual Page -- http://www.php.net/manual/en/function.mb-detect-encoding.php
Edit -- https://master.php.net/note/edit/89915
Del: integrated -- https://master.php.net/note/delete/89915/integrated
Del: useless -- https://master.php.net/note/delete/89915/useless
Del: bad code -- https://master.php.net/note/delete/89915/bad+code
Del: spam -- https://master.php.net/note/delete/89915/spam
Del: non-english -- https://master.php.net/note/delete/89915/non-english
Del: in docs -- https://master.php.net/note/delete/89915/in+docs
Del: other reasons-- https://master.php.net/note/delete/89915
Reject -- https://master.php.net/note/reject/89915
Search -- https://master.php.net/manage/user-notes.php