By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,021 Members | 952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,021 IT Pros & Developers. It's quick & easy.

Set JavaScript variable to DB contents

P: n/a
FP
Not sure if this post belogs here, but I'm hoping someone can help me
out.
I can get the contents of the my database comments field using PHP.
The comments field may include single or double quotes or other strange
characters.
How do I compensate for these problem characters when I try to set a
JavaScript variable? eg.

<SCRIPT LANGUAGE="JavaScript">
MyComments = " <? PHP result here?>"
</script>

Jul 4 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Rik
FP wrote:
Not sure if this post belogs here, but I'm hoping someone can help me
out.
I can get the contents of the my database comments field using PHP.
The comments field may include single or double quotes or other
strange characters.
How do I compensate for these problem characters when I try to set a
JavaScript variable? eg.

<SCRIPT LANGUAGE="JavaScript">
MyComments = " <? PHP result here?>"
</script>
addslashes()
Or maybe htmlentities() is a better choice here.

Grtz,
--
Rik Wasmus
Jul 4 '06 #2

P: n/a
*** FP escribió/wrote (4 Jul 2006 12:08:07 -0700):
How do I compensate for these problem characters when I try to set a
JavaScript variable? eg.

<SCRIPT LANGUAGE="JavaScript">
MyComments = " <? PHP result here?>"
</script>
Check the latest user note in:

http://www.php.net/htmlspecialchars

I don't really understand the code, anyway. You'll probably have enough
with:

http://www.php.net/addslashes

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 4 '06 #3

P: n/a
FP
Thanks, the "addslashes()" was exactly what I was looking for.

Jul 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.