note 101095 added to function.json-decode
| From: | contacto at hardcode dot com dot ar | Date: | Thu, 25 Nov 2010 21:53:56 +0000 |
| Subject: | note 101095 added to function.json-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174360@lists.php.net to get a copy of this message | ||
If you have a json encoded array that contains non UTF8 chars, this function will do the trick:
$array = json_decode(safeJSON_chars($iso_8859_1_data));
function safeJSON_chars($data) {
$aux = str_split($data);
foreach($aux as $a) {
$a1 = urlencode($a);
$aa = explode("%", $a1);
foreach($aa as $v) {
if($v!="") {
if(hexdec($v)>127) {
$data = str_replace($a,"&#".hexdec($v).";",$data);
}
}
}
}
return $data;
}
Of course it works if you want to show this inside a HTML page, so entities will be converted.
Hope this helps you as much as it helped me.
----
Server IP: 201.216.232.3
Probable Submitter: 190.55.170.233
----
Manual Page -- http://www.php.net/manual/en/function.json-decode.php
Edit -- https://master.php.net/note/edit/101095
Del: integrated -- https://master.php.net/note/delete/101095/integrated
Del: useless -- https://master.php.net/note/delete/101095/useless
Del: bad code -- https://master.php.net/note/delete/101095/bad+code
Del: spam -- https://master.php.net/note/delete/101095/spam
Del: non-english -- https://master.php.net/note/delete/101095/non-english
Del: in docs -- https://master.php.net/note/delete/101095/in+docs
Del: other reasons-- https://master.php.net/note/delete/101095
Reject -- https://master.php.net/note/reject/101095
Search -- https://master.php.net/manage/user-notes.php