You are here: Re: JS/PHP Integration « PHP Programming Language « IT news, forums, messages
Re: JS/PHP Integration

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация