On my site, I have a PHP script which takes multiple source files (HTML,CSS, and javascript), optimizes them, embeds them into a page, and caches them (basically compiling my website). Recently, I have added jquery-json (a jQuery plugin for encoding JSON into strings), but part of the code contains multiple slashes (used in some sort of a regex):
var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g,
When this line is processed by the script I mentioned earlier one of the backslashes is removed and results in:
var escapeable = /["\\x00-\x1f\x7f-\x9f]/g,
Also, I have setup a short script to make sure the problem is not being caused by something in the way that the javascript is being processed by the PHP script, and that it is in fact a issue with the way that PHP outputs it:
<?php
$string = 'var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g,';
echo($string); //this outputs: var escapeable = /["\\x00-\x1f\x7f-\x9f]/g,
?>
As you can see by the comment, the problem is the same in the simple script too...
I'm not sure if this is relevant, but I have checked to make sure that magic quotes are off. Also, I am aware of 'escapeable' being misspelled but, that's just the way it is in the jquery-json source code.
So, how do I prevent PHP from removing backslashes from the output?