note 126447 deleted from function.str-replace by salathe

From: Date: Tue, 21 Sep 2021 21:57:58 +0000
Subject: note 126447 deleted from function.str-replace by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216991@lists.php.net to get a copy of this message
Note Submitter: Alex C ---- Addtition to nikolaz dot tang answer: If your input array may ever contain Unicode symbols, do not forget to add JSON_UNESCAPED_UNICODE flag to json_encode(), or it won't work. Also you can add JSON_UNESCAPED_SLASHES if you want to str_replace some slashes. And as mrrehbein at gmail dot com noticed, there were second argument "true" in json_decode missed (without it json_decode returns objects, not arrays) Recommended way for multidimensional arrays: <?php function str_replace_json($search, $replace, $subject){ return json_decode(str_replace($search, $replace, json_encode($subject, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)), true); } ?>

« previous php.notes (#216991) next »