note 100492 added to function.json-encode
| From: | migprj at gmail dot com | Date: | Tue, 19 Oct 2010 14:46:10 +0000 |
| Subject: | note 100492 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173282@lists.php.net to get a copy of this message | ||
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:
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;
}
/* ....... */
----
Server IP: 69.147.83.197
Probable Submitter: 213.13.150.21
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/100492
Del: integrated -- https://master.php.net/note/delete/100492/integrated
Del: useless -- https://master.php.net/note/delete/100492/useless
Del: bad code -- https://master.php.net/note/delete/100492/bad+code
Del: spam -- https://master.php.net/note/delete/100492/spam
Del: non-english -- https://master.php.net/note/delete/100492/non-english
Del: in docs -- https://master.php.net/note/delete/100492/in+docs
Del: other reasons-- https://master.php.net/note/delete/100492
Reject -- https://master.php.net/note/reject/100492
Search -- https://master.php.net/manage/user-notes.php