note 84031 added to function.utf8-decode

From: Date: Tue, 24 Jun 2008 21:13:52 +0000
Subject: note 84031 added to function.utf8-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-140781@lists.php.net to get a copy of this message
EY! the bug is not in the function 'utf8_decode'. The bug is in the function 'mb_detect_encoding'. If you put a word with a special char at the end like this 'accentué', that will lead to a wrong result (UTF-8) but if you put another char at the end like this 'accentuée' you will get it right. So you should always add a ISO-8859-1 character to your string for this check. My advise is to use a blank space. I´ve tried it and it works! function ISO_convert($array) { $array_temp = array(); foreach($array as $name => $value) { if(is_array($value)) $array_temp[(mb_detect_encoding($name." ",'UTF-8,ISO-8859-1') == 'UTF-8' ? utf8_decode($name) : $name )] = ISO_convert($value); else $array_temp[(mb_detect_encoding($name." ",'UTF-8,ISO-8859-1') == 'UTF-8' ? utf8_decode($name) : $name )] = (mb_detect_encoding($value." ",'UTF-8,ISO-8859-1') == 'UTF-8' ? utf8_decode($value) : $value ); } return $array_temp; } ---- Server IP: 69.147.83.197 Probable Submitter: 200.69.136.160 ---- Manual Page -- http://www.php.net/manual/en/function.utf8-decode.php Edit -- https://master.php.net/note/edit/84031 Del: integrated -- https://master.php.net/note/delete/84031/integrated Del: useless -- https://master.php.net/note/delete/84031/useless Del: bad code -- https://master.php.net/note/delete/84031/bad+code Del: spam -- https://master.php.net/note/delete/84031/spam Del: non-english -- https://master.php.net/note/delete/84031/non-english Del: in docs -- https://master.php.net/note/delete/84031/in+docs Del: other reasons-- https://master.php.net/note/delete/84031 Reject -- https://master.php.net/note/reject/84031 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140781) next »