note 101095 deleted from function.json-decode by googleguy

From: Date: Fri, 30 Nov 2012 05:45:00 +0000
Subject: note 101095 deleted from function.json-decode by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192220@lists.php.net to get a copy of this message
Note Submitter: contacto at hardcode dot com dot ar ---- If you have a json encoded array that contains non UTF8 chars, this function will do the trick: <?php $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.

« previous php.notes (#192220) next »