note 106417 added to function.json-encode

From: Date: Tue, 08 Nov 2011 15:59:30 +0000
Subject: note 106417 added to function.json-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-184332@lists.php.net to get a copy of this message
When you have trouble with json_encode and German umlauts. json_encode converts Strings to NULL when detecting umlauts not being UTF8encoded. Here's another recursive UTF8 conversion function and vice-versa. The object handling might be buggy but works for me. function array_utf8_encode_recursive($dat) { if (is_string($dat)) { return utf8_encode($dat); } if (is_object($dat)) { $ovs= get_object_vars($dat); $new=$dat; foreach ($ovs as $k =>$v) { $new->$k=array_utf8_encode_recursive($new->$k); } return $new; } if (!is_array($dat)) return $dat; $ret = array(); foreach($dat as $i=>$d) $ret[$i] = array_utf8_encode_recursive($d); return $ret; } function array_utf8_decode_recursive($dat) { if (is_string($dat)) { return utf8_decode($dat); } if (is_object($dat)) { $ovs= get_object_vars($dat); $new=$dat; foreach ($ovs as $k =>$v) { $new->$k=array_utf8_decode_recursive($new->$k); } return $new; } if (!is_array($dat)) return $dat; $ret = array(); foreach($dat as $i=>$d) $ret[$i] = array_utf8_decode_recursive($d); return $ret; } ---- Server IP: 212.124.37.9 Probable Submitter: 217.92.55.85 ---- Manual Page -- http://www.php.net/manual/en/function.json-encode.php Edit -- https://master.php.net/note/edit/106417 Del: integrated -- https://master.php.net/note/delete/106417/integrated Del: useless -- https://master.php.net/note/delete/106417/useless Del: bad code -- https://master.php.net/note/delete/106417/bad+code Del: spam -- https://master.php.net/note/delete/106417/spam Del: non-english -- https://master.php.net/note/delete/106417/non-english Del: in docs -- https://master.php.net/note/delete/106417/in+docs Del: other reasons-- https://master.php.net/note/delete/106417 Reject -- https://master.php.net/note/reject/106417 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184332) next »