|
Posted by Christoph Burschka on 04/27/07 14:48
Martin Honnen schrieb:
> 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).
>
>
Actually, it's not JS that turns "\n" into a newline, it's PHP.
If single quotes (like below) don't make it go away, *then* it's time to
look for ways to escape it on the Javascript side; not before.
>> <?php $phpfoo = 'a\nb\nc'; ?>
>> var jsfoo = "<?php echo $phpfoo;?>";
--
cb
[Back to original message]
|