[Javascript] String on multiple lines
Paul Novitski
paul at juniperwebcraft.com
Mon Jun 19 18:28:51 CDT 2006
At 03:45 PM 6/19/2006, Paul Novitski wrote:
>I'd try escaping the PHP line breaks, replacing \n with \\n, so that
>they output into your HTML (JavaScript) source as the literal string
>"\n" instead of the line-break character.
>
> var variable = "<?php echo str_replace("\n", "\\n", $variable); ?>";
Oops, I meant:
var variable = "<?php echo str_replace("\\n", "\\\\n",
$variable); ?>";
Any case in which you're referring to the backslash character, and
not its effect on the subsequent character, it needs to be escaped
with a second backslash.
Paul
More information about the Javascript
mailing list