i want to read a .json file using file_get_contents which returns a string. Then i use json_decode to create an array/object of it. Everything works.
My problem is that sometimes the string in the json file includes regex expressions. These can not be decoded! Therefore the following notice message:
Notice: Trying to get property 'Data' of non-object in
After a quick google search i found out that i have to double escape them. I tried to change it in the json file - it works.
From:
"Block Proxy URL": "somesite.ab123regex(\d\d\d).top/fyli.php",
To:
"Block Proxy URL": "somesite.ab123regex(\\d\\d\\d).top/fyli.php",
But i receive that file generated by an appliance so i can't change it every time manually.
So consequently i tried to automate it:
$archer_json_data = file_get_contents($filename);
str_replace("\\", "\\\\", $archer_json_data);
$archer_json_array = json_decode($archer_json_data)->Data;
which does not work. I also tried addslashes instead of str_replace, it does not work. why? According to the replies of my quick google search it works for them.
For debugging purposes i echo'ed archer_json_data
before str_replace and after.. they are exactly the same. Why does my str_replace not work?