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
Share on other sites

[quote author=jvrothjr link=topic=100597.msg397241#msg397241 date=1152909371]
its all in the " ' single and doule quote

[/quote]

Yes it is.  And the escaping slashes.  But it's really eluding me...
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.