Solved

How to echo image button in php

Posted on 2009-04-07
5
1,548 Views
Last Modified: 2012-05-06
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
Comment
Question by:RupertA
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 250 total points
Comment Utility
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
 
LVL 9

Assisted Solution

by:LinuxNubb
LinuxNubb earned 250 total points
Comment Utility
You can also escape all double quotes inside your double quote string, example:

echo "< img src=\"img.gif\"";
0
 
LVL 9

Expert Comment

by:LinuxNubb
Comment Utility
Sorry, cxr, I missed your escapted double quotes.  Points to CXR!
0
 
LVL 39

Expert Comment

by:Roger Baklund
Comment Utility
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
 

Author Comment

by:RupertA
Comment Utility
thanks guys!

I went with \ before the double quotes. Works fine.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now