Set JavaScript variable to DB contents

This is a discussion on Set JavaScript variable to DB contents within the PHP Language forums, part of the PHP Programming Forums category; Not sure if this post belogs here, but I'm hoping someone can help me out. I can get the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-04-2006
FP
 
Posts: n/a
Default Set JavaScript variable to DB contents

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>

Reply With Quote
  #2 (permalink)  
Old 07-04-2006
Rik
 
Posts: n/a
Default Re: Set JavaScript variable to DB contents

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


Reply With Quote
  #3 (permalink)  
Old 07-04-2006
Alvaro G. Vicario
 
Posts: n/a
Default Re: Set JavaScript variable to DB contents

*** 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
--
Reply With Quote
  #4 (permalink)  
Old 07-04-2006
FP
 
Posts: n/a
Default Re: Set JavaScript variable to DB contents

Thanks, the "addslashes()" was exactly what I was looking for.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:31 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0