I’m pulling JSON from Instagram:
$instagrams = json_decode($response)->data;
Then parsing variables into a PHP array to restructure the data, then re-encoding and caching the file:
file_put_contents($cache,json_encode($results));
When I open the cache file all my forward slashes “/” are being escaped:
http:\/\/distilleryimage4.instagram.com\/410e7...
I gather from my searches that json_encode() automatically does this…is there a way to disable it?
Yes, you only need to use the
JSON_UNESCAPED_SLASHESflag (PHP 5.4+).If you don’t have PHP 5.4 at hand (you certainly already asserted the warning above), pick one of the many existing functions and modify them to your needs, e.g. http://snippets.dzone.com/posts/show/7487 (archived copy).
Example Demo
Example Output: