Solved

How to echo image button in php

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
This article discusses how to implement server side field validation and display customized error messages to the client.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

695 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