Jump to content

Echoing a javascript


Aesop

Recommended Posts

Hello,

Having a tricky problem with this snippet.  Here is the original source, not echoed yet;

[code]<a href="#" onmouseover="popup('<img src=$folder\$fullsized>')" onmouseout="popout()"><img src=$folder\$thumbnail></a><br />[/code]

Ok, here it is attempted to be echoed;

[code=php:0]echo "<a href=\"stuff.php\" onmouseover=\"popup('<img src=\"$folder\$fullsized\">')\" onmouseout=\"popout()\">'<img src=\"$folder\$thumbnail\">'</a><br />";[/code]

on the page it spits out

[i]')" onmouseout="popout()">' [/i] followed by the 2nd image

Any suggestions?  :-\
Link to comment
https://forums.phpfreaks.com/topic/14613-echoing-a-javascript/
Share on other sites

in general, when you're going to be echoing a lot more HTML than variables, i would suggest using single quotes to delimit the string:

echo '<a href="#" onmouseover="popup(\'<img src='.$folder.'\\'.$fullsized.'>\')" onmouseout="popout()"><img src='.$folder.'\\'.$thumbnail.'></a><br />';

in this case, i think escaping the single quotes is the lesser of the evils.

the other thing to point out is the backslash.  backslash is a general escape character; to get a LITERAL backslash printed, you need to escape the backslash with a backslash (whee).  otherwise, the backslash would be interpreted as escaping the '$' of $fullsized and $thumbnail, which would turn THEM into literals (ie. '$fullsized' rather than its value).
Link to comment
https://forums.phpfreaks.com/topic/14613-echoing-a-javascript/#findComment-58123
Share on other sites

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.