Reply to Re: String in php and js script

Your name:

Reply:


Posted by steve.high on 12/09/07 05:20

It's generally considered best practices to wrap HTML elements in
double quotes.
So, your onclick event handler should look like this:

onclick="js_test('<?php echo $string; ?>');"

(Note that it is also considered good form to use <?php ... ?> to
denote PHP code at all times.)

Depending on the contents of $string, you might also want to use the
addslashes() function, like so...
onclick="js_test('<?php echo addslashes($string); ?>');"

Hope this helps.

On Dec 8, 9:51 pm, php_mysql_beginer911 <deepa...@gmail.com> wrote:
> Hi everyone ..
> i am trying to use a string which was saved by php form and contain
> single quote ' or double quote
>
> " .. when i using that string in my js script function like
> function
>
> onclick='js_test("<?=$string;?>")'
>
> if $string contains double quote it will simply break the function ..
> and same goes for single quote if i
>
> surround $string with single quote i tried using escape and unescape
> but that means .. every place i am using php ddata which might contain
> single or double quote i have to use those javascript
>
> function . as i am very new to programming if somebody could advise
> what is the best way to deal
>
> with string when we use js script and php
>
> hope you can understand my english and hope somebody will reply soon
>
> thanks

[Back to original 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

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