note 106556 added to function.json-encode
| From: | me dot pierB at osu1 dot php dot net | Date: | Fri, 18 Nov 2011 10:33:36 +0000 |
| Subject: | note 106556 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184558@lists.php.net to get a copy of this message | ||
Combining last 2 comments, json_decode and json_encode can gain great advantages from following:
function array_ut8_encode_recursive(&$itm) {
$new = $itm;
if (is_string($new)) return utf8_encode($new);
if (is_array($new)) return array_map('array_ut8_encode_recursive', $new);
if (is_object($new)) foreach (get_object_vars($new) as $key) $new->$key =
array_ut8_encode_recursive($new->$key);
return $new;
} // array_ut8_encode_recursive()
function array_ut8_decode_recursive(&$itm) {
$new = $itm;
if (is_string($new)) return utf8_decode($new);
if (is_array($new)) return array_map('array_ut8_decode_recursive', $new);
if (is_object($new)) foreach (get_object_vars($new) as $key) $new->$key =
array_ut8_decode_recursive($new->$key);
return $new;
} // array_ut8_decode_recursive()
so you do this:
json_encode(array_ut8_encode_recursive($data))
----
Server IP: 69.147.83.197
Probable Submitter: 82.186.97.114
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/106556
Del: integrated -- https://master.php.net/note/delete/106556/integrated
Del: useless -- https://master.php.net/note/delete/106556/useless
Del: bad code -- https://master.php.net/note/delete/106556/bad+code
Del: spam -- https://master.php.net/note/delete/106556/spam
Del: non-english -- https://master.php.net/note/delete/106556/non-english
Del: in docs -- https://master.php.net/note/delete/106556/in+docs
Del: other reasons-- https://master.php.net/note/delete/106556
Reject -- https://master.php.net/note/reject/106556
Search -- https://master.php.net/manage/user-notes.php