note 126446 added to function.str-replace
| From: | AlexC at main dot php dot net | Date: | Tue, 21 Sep 2021 21:29:54 +0000 |
| Subject: | note 126446 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216988@lists.php.net to get a copy of this message | ||
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)));
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 128.70.4.219)
----
Manual Page -- https://php.net/manual/en/function.str-replace.php
Edit -- https://main.php.net/note/edit/126446
Del: integrated -- https://main.php.net/note/delete/126446/integrated
Del: useless -- https://main.php.net/note/delete/126446/useless
Del: bad code -- https://main.php.net/note/delete/126446/bad+code
Del: spam -- https://main.php.net/note/delete/126446/spam
Del: non-english -- https://main.php.net/note/delete/126446/non-english
Del: in docs -- https://main.php.net/note/delete/126446/in+docs
Del: other reasons-- https://main.php.net/note/delete/126446
Reject -- https://main.php.net/note/reject/126446
Search -- https://main.php.net/manage/user-notes.php