json_encode() escaping forward slashes
is there a way to disable it?
Yes, you only need to use the
!important read before: https://stackoverflow.com/a/10210367/367456 (know what you're dealing with - know your enemy)
If you don't have PHP 5.4 at hand, pick one of the many existing functions and modify them to your needs, e.g. http://snippets.dzone.com/posts/show/7487 (archived copy).
/* * Escaping the reverse-solidus character ("/", slash) is optional in JSON. * * This can be controlled with the JSON_UNESCAPED_SLASHES flag constant in PHP. * * @link http://stackoverflow.com/a/10210433/367456 */ $url = 'http://www.example.com/';echo json_encode($url), "\n";echo json_encode($url, JSON_UNESCAPED_SLASHES), "\n";
On the flip side, I was having an issue with PHPUNIT asserting urls was contained in or equal to a url that was json_encoded -
would be encoded to:
If you need to do a comparison, transforming the url using:
allowed for the proper output during my comparisons.