note 126446 deleted from function.str-replace by salathe
| From: | salathe@php.net | Date: | Tue, 21 Sep 2021 21:57:46 +0000 |
| Subject: | note 126446 deleted from function.str-replace by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216990@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.
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)));
}
?>