How to echo image button in php

Posted on 2009-04-07
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


which should of course really be


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

Question by:RupertA
  • 2
  • 2
LVL 39

Accepted Solution

Roger Baklund earned 250 total points
ID: 24087636
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


Assisted Solution

LinuxNubb earned 250 total points
ID: 24087671
You can also escape all double quotes inside your double quote string, example:

echo "< img src=\"img.gif\"";

Expert Comment

ID: 24087684
Sorry, cxr, I missed your escapted double quotes.  Points to CXR!
LVL 39

Expert Comment

by:Roger Baklund
ID: 24087834
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();">'.


Open in new window


Author Comment

ID: 24088010
thanks guys!

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction This article is intended for those who are new to PHP error handling (  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

19 Experts available now in Live!

Get 1:1 Help Now