Jump to content

Trouble with quotes when setting PHP variable = Javascript Method


ridiculous

Recommended Posts

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?

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>";

?>

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?

<?

$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

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.

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.