Hi. I am trying to get an rollover image (code from dreamweaver) to work inside of php code. I am having troubles with ' or " } echo '<a href="http://example-url.com/index.php?task=logout" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnlogout','','http://example-url.com/template/images/button_logout_roll.png',1)"><img src="http://example-url.com/template/images/button_logout.png" name="btnlogout" width="88" height="30" border="0" id="btnlogout" /></a>'; } else { PHP: this is what I get: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' I have no clue how to get this working. thnx in advance.
You don't have to use the echo tag here just use my code. } ?> <a href="http://example-url.com/index.php?task=logout" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnlogout','','http://example-url.com/template/images/button_logout_roll.png',1)"><img src="http://example-url.com/template/images/button_logout.png" name="btnlogout" width="88" height="30" border="0" id="btnlogout" /></a> <? } else { PHP:
after the } else { PHP: comes a different rollover image, and with your code it seems that the "if" "else" does get cutt off, so it shows me both rollover images, instead of just one of them. here is the full code
Hey if you are using quotes ("") around your strings, and you want to use quotes ("") inside those strings, but don't want them to be part of the code to be executed, you can use the backslash / to escape them. The same is true if you are using apostrophes '.
this is your problem line: echo '<a href="http://example-url.com/index.php?task=logout" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnlogout','','http://example-url.com/template/images/button_logout_roll.png',1)"><img src="http://example-url.com/template/images/button_logout.png" name="btnlogout" width="88" height="30" border="0" id="btnlogout" /></a>'; you encapsulate the echoed string in single quotes. then later on where you define the inline javascript, you have other instances of single quotes, like: 'btnlogout','',' these need to be escaped by adding a slash like so: \'btnlogout\',\'\',\'... etc etc, otherwise PHP compiler registers the end of your string and tries to eval the next bit, which happens to be 'btnlogout'. i hope this explains why you get the error and helps you understand how to avoid repeating it
Just like dimitar christoff said.. An easier way to show it: You got this code: <? echo "Hello "world". This is a test."; ?> PHP: You can see.. Your echo starts with " and around the word world, we have " and ". Those will break your echo, because the compiler thinks it ends at the first " (echo "hello world". But since it cannot find ; after the echo, it will return false. So you have to escape the string by putting \ in front of any ". So: <? echo "Hello \"world\". This is a test"; ?> PHP: If you use ' instead of ", you'll have to use backslash in front of every ', but not ": <? echo 'Hello "world". This is a test.'; //This one will work. echo 'Hello 'world'. This is a test.'; //This one will NOT work. echo "Hello 'world'. This is a test.'; //This one will work. echo "Hello "world". This is a test."; //This one will NOT work. //Escaped: echo "Hello \"world\". This is a test"; //This one will work echo 'Hello \'world\'. This is a test"; //This one works too ?> PHP: