note 99837 added to function.json-encode
| From: | Dave-s10sys dot com at osu1 dot php dot net | Date: | Thu, 09 Sep 2010 15:46:40 +0000 |
| Subject: | note 99837 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172428@lists.php.net to get a copy of this message | ||
This may help others who are seeing null strings returned by json_encode().
This function will encode all array values to utf8 so they are safe for json_encode();
usage:
json_encode(utf8json($dataArray));
function utf8json($inArray) {
static $depth = 0;
/* our return object */
$newArray = array();
/* safety recursion limit */
$depth ++;
if($depth >= '30') {
return false;
}
/* step through inArray */
foreach($inArray as $key=>$val) {
if(is_array($val)) {
/* recurse on array elements */
$newArray[$key] = utf8json($inArray);
} else {
/* encode string values */
$newArray[$key] = utf8_encode($val);
}
}
/* return utf8 encoded array */
return $newArray;
}
----
Server IP: 69.147.83.197
Probable Submitter: 86.152.13.147
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/99837
Del: integrated -- https://master.php.net/note/delete/99837/integrated
Del: useless -- https://master.php.net/note/delete/99837/useless
Del: bad code -- https://master.php.net/note/delete/99837/bad+code
Del: spam -- https://master.php.net/note/delete/99837/spam
Del: non-english -- https://master.php.net/note/delete/99837/non-english
Del: in docs -- https://master.php.net/note/delete/99837/in+docs
Del: other reasons-- https://master.php.net/note/delete/99837
Reject -- https://master.php.net/note/reject/99837
Search -- https://master.php.net/manage/user-notes.php