Solved

How to echo image button in php

Posted on 2009-04-07
5
1,549 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
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 250 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

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 (http://www.experts-exchange.com/A_2902.html) 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 (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…
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