I’m wondering if anyone knows of a PHP setting that will automatically escape double quotes.
My issue is that on my local server, i’m posting this string to the server:
{"0":{"id":"19","goal":"34"},"1":{"id":"22","goal":"657675"},"2":{"id":"21","goal":"456"}}
and it works fine. However, on the production server, I post the same string, and when I echo it out it is changed to:
{\"0\":{\"id\":\"19\",\"goal\":\"34\"},\"1\":{\"id\":\"22\",\"goal\":\"657675\"},\"2\":{\"id\":\"21\",\"goal\":\"456\"}}
I managed to fix it with a string_replace() call, but I would like to know why this is happening. The production server and local server are using the same code and were updated to use the same data, so I’m assuming the discrepency must be caused by server settings, but I have never heard of a setting that does that.
Has anyone experienced something like this?
Yes. It’s called Magic Quotes:
http://php.net/manual/en/security.magicquotes.php
http://php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc
You generally want to turn this off, and manually handle escaping as necessary.