0

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?

1 Answer 1

1

You may use the nowdoc-syntax(requires PHP 5.3.0 ):

$string = <<<'EOD'
var  escapeable = /["\\\x00-\x1f\x7f-\x9f]/g,
EOD;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.