note 99837 deleted from function.json-encode by cmb

From: Date: Sun, 04 Nov 2018 09:54:14 +0000
Subject: note 99837 deleted from function.json-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209598@lists.php.net to get a copy of this message
Note Submitter: Dave - s10sys.com ---- 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: <?php 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($val); } else { /* encode string values */ $newArray[$key] = utf8_encode($val); } } /* return utf8 encoded array */ return $newArray; } ?> [NOTE BY danbrown AT php DOT net: Includes a bugfix by (robbiz233 AT hotmail DOT com) on 18-SEP-2010, to replace: $newArray[$key] = utf8json($inArray); with: $newArray[$key] = utf8json($val);" in the given function.]

« previous php.notes (#209598) next »