note 113037 deleted from function.json-encode by cmb

From: Date: Tue, 05 Nov 2019 14:30:00 +0000
Subject: note 113037 deleted from function.json-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212930@lists.php.net to get a copy of this message
Note Submitter: kvz at php dot net ---- json_encode "only works with UTF-8 encoded data." so if there is any chance that users influence the variable you're about to encode to json, you should first recursively encode to UTF-8. There are several comments doing that, but some only traverse the input array 1 level deep. Others write full fledged recursive functions themselves. Whereas as of PHP5 you could also utilize array_walk_recursive <?php array_walk_recursive($inputArray, function(&$val) { $val = utf8_encode($val); }); json_encode($inputArray); ?> Hope this helps

« previous php.notes (#212930) next »