ridiculous Posted March 30, 2008 Share Posted March 30, 2008 As you can see, the quotation marks on the code given are incorrect. $php_var = "<td onMouseOver="this.className='A';">" I need to have double and single quotes to get the javascript to work correctly, but don't know how to do this correctly. Probably simple. Anyone know how to fix this and where to look at the documentation on php.net? Link to comment https://forums.phpfreaks.com/topic/98585-trouble-with-quotes-when-setting-php-variable-javascript-method/ Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 have a look at the concept then apply to your own code... sorry dont do javascript anymore babys scripting lanuage.... <?php $address=" "; $text=" "; echo "<a href='$address' onmouseover='test(" {$text} " )'>bbc</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/98585-trouble-with-quotes-when-setting-php-variable-javascript-method/#findComment-504545 Share on other sites More sharing options...
ridiculous Posted March 30, 2008 Author Share Posted March 30, 2008 Thanks but the issue that I have involves using double and single quotes in the javascript. In your example, you merely use all single quotes rather than using both single and double. $php = '<div onMouseOver="this.ClassName=' I have a problem with PHP when I do this. Aren't you supposed to use / somewhere in there? Link to comment https://forums.phpfreaks.com/topic/98585-trouble-with-quotes-when-setting-php-variable-javascript-method/#findComment-504548 Share on other sites More sharing options...
ridiculous Posted March 30, 2008 Author Share Posted March 30, 2008 <? $try = '<td onMouseOver="this.style.backgroundColor='blue';"> Lolly. </td>'; ?> RESULT: Parse error: syntax error, unexpected T_STRING in C:\Documents and Settings\The Pawn\Desktop\Test Server\Reservations Calendar\the_table.php on line 3 Link to comment https://forums.phpfreaks.com/topic/98585-trouble-with-quotes-when-setting-php-variable-javascript-method/#findComment-504549 Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 try that mate.............\ <?php $php_var = "<td onMouseOver=\"this.className='A';\">"; ?> Link to comment https://forums.phpfreaks.com/topic/98585-trouble-with-quotes-when-setting-php-variable-javascript-method/#findComment-504550 Share on other sites More sharing options...
ridiculous Posted March 30, 2008 Author Share Posted March 30, 2008 You are awesome, thank you. How do you know where to put the slashes? Is there documentation on this on PHP.net somewhere? Link to comment https://forums.phpfreaks.com/topic/98585-trouble-with-quotes-when-setting-php-variable-javascript-method/#findComment-504553 Share on other sites More sharing options...
ridiculous Posted March 30, 2008 Author Share Posted March 30, 2008 Topic is solved, but for some reason I do not see the "topic solved button" anywhere. Link to comment https://forums.phpfreaks.com/topic/98585-trouble-with-quotes-when-setting-php-variable-javascript-method/#findComment-504557 Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 in other words always escape double \" quotes <?php //error not \ escaped " double quote //echo " hi there i "am" redarrow"; //no error but your see the " double quote escaped double quote echo " hi there i \"am\" redarrow"; //error not escaped ' single quote //echo 'hi there i 'am' redarrow'; //no error but your see the ' single quote escaped ' echo 'hi there i \'am\' redarrow'; // so if it starts with a " double quote and a following double quote //then \ use a backspace to escape the quoted mark. ?> Link to comment https://forums.phpfreaks.com/topic/98585-trouble-with-quotes-when-setting-php-variable-javascript-method/#findComment-504559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.