note 100492 deleted from function.json-encode by cmb

From: Date: Sun, 04 Nov 2018 09:54:28 +0000
Subject: note 100492 deleted from function.json-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209599@lists.php.net to get a copy of this message
Note Submitter: migprj at gmail dot com ---- Because json_encode() only deals with utf8, it is often necessary to convert all the string values inside an array to utf8. I've created these two functions: <?php function utf8_encode_all($dat) // -- It returns $dat encoded to UTF8 { if (is_string($dat)) return utf8_encode($dat); if (!is_array($dat)) return $dat; $ret = array(); foreach($dat as $i=>$d) $ret[$i] = utf8_encode_all($d); return $ret; } /* ....... */ function utf8_decode_all($dat) // -- It returns $dat decoded from UTF8 { if (is_string($dat)) return utf8_decode($dat); if (!is_array($dat)) return $dat; $ret = array(); foreach($dat as $i=>$d) $ret[$i] = utf8_decode_all($d); return $ret; } /* ....... */ ?>

« previous php.notes (#209599) next »