?
Solved

How to echo image button in php

Posted on 2009-04-07
5
Medium Priority
?
1,554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 1000 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

0
 
LVL 9

Assisted Solution

by:LinuxNubb
LinuxNubb earned 1000 total points
ID: 24087671
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
ID: 24087684
Sorry, cxr, I missed your escapted double quotes.  Points to CXR!
0
 
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();">'.
     '</div>';

Open in new window

0
 

Author Comment

by:RupertA
ID: 24088010
thanks guys!

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

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

765 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