note 106417 deleted from function.json-encode by cmb

From: Date: Sun, 04 Nov 2018 10:04:08 +0000
Subject: note 106417 deleted from function.json-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209605@lists.php.net to get a copy of this message
Note Submitter: mmi at uhb-consulting dot de ---- 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. <?php 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; } ?>

« previous php.notes (#209605) next »