note 89316 deleted from function.utf8-decode by thiago
| From: | thiago@php.net | Date: | Tue, 03 Mar 2009 13:43:36 +0000 |
| Subject: | note 89316 deleted from function.utf8-decode by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-151386@lists.php.net to get a copy of this message | ||
Note Submitter: Ruud Altenburg
----
Just a note to the function posted by haugas at gmail dot com:
A script using this function seemed to hang for a reason not immediately clear. It appeared that the
string that was being parsed contained an odd character that caused an eternal loop. Therefore you
might want to provide an escape route:
function _utf8_decode($string) {
$tmp = $string;
$count = 0;
while (mb_detect_encoding($tmp) == "UTF-8") {
$tmp = utf8_decode($tmp);
$count++;
if ($count > 25) {
return $string;
}
}
for ($i = 0; $i < $count - 2 ; $i++) {
$string = utf8_decode($string);
}
return $string;
}