Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1560
  • Last Modified:

How to echo image button in php

Want to echo this image button to my html page

echo "<div style='position:absolute; left:615; top:93; cursor:hand;'>
<img src='images_user_progress/up_back_n.gif'  onMouseOver='src='images_user_progress/up_back_o.gif'' onMouseOut='src='images_user_progress/up_back_n.gif''  border='0' onClick='back_to_user_progress();'>
</div> ";

The reason why they are all single quotes is because my understanding is that when using echo "  ";, then everything inside must be single quotes. Of course my code above does not work because of

onMouseOver='src='images_user_progress/up_back_o.gif''

which should of course really be

onMouseOver="src='images_user_progress/up_back_o.gif'"


which would work. Is there a way to get round this? thanks
echo "<div style='position:absolute; left:615; top:93; cursor:hand;'>
<img src='images_user_progress/up_back_n.gif'  onMouseOver='src='images_user_progress/up_back_o.gif'' onMouseOut='src='images_user_progress/up_back_n.gif''  border='0' onClick='back_to_user_progress();'>
</div> ";

Open in new window

0
RupertA
Asked:
RupertA
  • 2
  • 2
2 Solutions
 
Roger BaklundCommented:
There are several ways to get around this. You can split it in several echo statements, or prepend " characters with a backslash within the double quotes:
echo "<div style='position:absolute; left:615; top:93; cursor:hand;'>
<img src='images_user_progress/up_back_n.gif'  onMouseOver=\"src='images_user_progress/up_back_o.gif';\" onMouseOut=\"src='images_user_progress/up_back_n.gif'\"  border='0' onClick='back_to_user_progress();'>
</div> ";
 
# You can also use apostrophes for the outer string, and escape those with backslashes:
 
echo '<div style="position:absolute; left:615; top:93; cursor:hand;">
<img src="images_user_progress/up_back_n.gif" onMouseOver="src=\'images_user_progress/up_back_o.gif\';" onMouseOut="src=\'images_user_progress/up_back_n.gif\'"  border="0" onClick="back_to_user_progress();">
</div> ';

Open in new window

0
 
LinuxNubbCommented:
You can also escape all double quotes inside your double quote string, example:

echo "< img src=\"img.gif\"";
0
 
LinuxNubbCommented:
Sorry, cxr, I missed your escapted double quotes.  Points to CXR!
0
 
Roger BaklundCommented:
Another possible syntax, without backslashes:
echo '<div style="position:absolute; left:615; top:93; cursor:hand;">'.
     '<img src="images_user_progress/up_back_n.gif" '.
          'onMouseOver="src='."'images_user_progress/up_back_o.gif'".'" '.
          'onMouseOut="src='."'images_user_progress/up_back_n.gif'".'"  '.
          'border="0" onClick="back_to_user_progress();">'.
     '</div>';

Open in new window

0
 
RupertAAuthor Commented:
thanks guys!

I went with \ before the double quotes. Works fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now