Posted by Martin Honnen on 04/27/07 14:43
ashore wrote:
> Say I'm using a snippet like
> $phpfoo = "a\nb\nc";
> var jsfoo = "<?php echo $phpfoo;?>";
>
> This errors out because JS sees the newline, and it needs to be
> escaped somehow. (In my real case, $phpfoo came from MySQL, and it's
> retrieved and displayed OK.)
PHP has addslashes e.g.
var jsfoo = "<?php echo addslashes($phpfoo); ?>";
that should help (although it is there in PHP to deal with escaping
strings for data base stuff).
--
Martin Honnen
http://JavaScript.FAQTs.com/
Navigation:
[Reply to this message]
|