www.webdeveloper.com
Results 1 to 5 of 5

Thread: having trouble passing value from php to javascript because of the quotation mark.

  1. #1
    Join Date
    Nov 2011
    Posts
    37

    having trouble passing value from php to javascript because of the quotation mark.

    Hi,

    I have something like this

    Code:
    <?php
    
    $var1 = "hello world &quot hello world"; // var1 get the value from sql. this is just some make up data.
    
    
    print <<<EOF
    
    <a href="#" onclick="test('$var1')">click me</a> // the problem i have is here.
     I want it to be test( "hello world &quot hello world") but it turned out to be test( "hello world " hello world"). 
    EOF;
    
    ?>
    Any idea how can I get this to work?
    Last edited by byebyebyezzz; 03-20-2012 at 11:12 AM.

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    You could always use replace to insert a \ before the &quot;
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  3. #3
    Join Date
    Nov 2011
    Posts
    37
    I tried /" before but I never tried /&quot. I ll give it a try tomorrow.
    thx

  4. #4
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    265
    Quote Originally Posted by byebyebyezzz View Post
    I tried /" before but I never tried /&quot. I ll give it a try tomorrow.
    thx
    No, that slash is the wrong direction. Try the one that should be above the enter/return key on your keyboard... it goes from upper-left to lower-right...

  5. #5
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234
    Use single quotes:
    Code:
     
    $var='x and y &quot plus 2'
    Php interprets anything between double quotes, but not between single quotes. Php will interpret between single quotes in heredocs.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles