How to Pass string with quotes from PHP to Javascript?

Ugnius_S

New member
Hi,

I've made a little example what does not work for me, here:
http://pastebin.com/CB2gLzPh

I'm trying to pass an array of strings to javascript, strings may or may not have quotes and double qoutes. What's the correct way to preprocess them using PHP. What function should I use, I've tried addslashes but this does'nt work.

Thank you.
In my example Test Two and Four fails as it has single quotes in it.
I've done some research it seems json_encode function should be used to pass PHP variables to JavaScript, and in this case I used htmlspecialchars function on top of json_encode to solve the problem when HTML Atrribute Value terminates before java script string is finished if ' is used in string
 
Back
Top