There is a json file saved in a string like {"Org1": [{"a": 1, "b": 2}, {...} ...]} (file name is file.json)
More visual view:
{ "Org1": [ { "a": 1, "b": 2 }, { "a": 12, "b": 345 }, { "a": 12364, "b": -1 } ], "Org2": [ ] } You need to change "Org1" to "Org123", without changing the order. The values "Org1" and "Org123" in the form of the variables "$ SchoolOldName" and "$ SchoolName" are correspondingly.
Problem:
$file = "file.json"; $json = json_decode(file_get_contents("$file"), true); $json = str_replace($SchoolOldName, $SchoolName, $json); file_put_contents("$file", json_encode($json)); In this embodiment, nothing works.
If you do without json_decode / json_encode - just through file_get_contents, then everything works until "Org1" is written in Russian characters. Then, without json_encode, the name would be "\ u0410 \ u0432 \ u0430 \ u043b \ u043e \ u043d" and str_replace will not work.
Tell me, please, how to transcode json string into Russian text (so that it remains a string, not an array)? Or how to make a working version of the replacement values using json_decode?
$jsonLectures = preg_replace("/\"$SchoolOldName\"/m", "\"$SchoolName\"", $jsonLectures);on$jsonLectures = str_replace($SchoolOldName, $SchoolName, $jsonLectures);Now the json file does not break, but the Russian values still do not change for some reason ... - Ya_O