Jump to content

load image


gobblegob

Recommended Posts

hello coders,

This is my first post here, well actually with PHP as i have only been messing with it for 1 week, but i do have good knowledge of vb.net, anyways....

Then problem i have is an extremely basic and embarrassing  :-[       

after i send an email with my script if successful then show one image if unsuccessful show another.

 

This is my code that works...

<?php echo $mail_sent ? "An email has been sent to you." : "Mail has failed.";?>

 

This is what i am trying to do....

<?php echo $mail_sent ? "An email has been sent to you.<img src="images/green_tick.gif" width="20" height="20" />" : "Mail has failed.<img src="images/failed.gif" width="20" height="20" />"";?>

Link to comment
https://forums.phpfreaks.com/topic/199746-load-image/
Share on other sites

As i'm sure what is a necessity of programming language, is maintaining the integrety of strings. PHP is based off of C, So it's not too alien, Just escape:

<?php 
  echo $mail_sent ? "An email has been sent to you.<img src=\"images/green_tick.gif\" width=\"20\" height=\"20\" />" : "Mail has failed. <img src=\"images/failed.gif\" width=\"20\" height=\"20\" />";
?>

Or of course you can use single quotes, either to wrap or to use within double quotes:

<?php 
  echo $mail_sent ? 'An email has been sent to you.<img src="images/green_tick.gif" width="20" height="20" />' : 'Mail has failed.<img src="images/failed.gif" width="20" height="20" />';
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/199746-load-image/#findComment-1048391
Share on other sites

Thanks alot guys  :D , so what does the backslash do ? src=\  please dont flame me lol

 

Oh, I came from a VB.NET background from 4-5 years back but must've forgotten how the more simple things were done.

 

A backslash is an escape entity, Well, best I show you a tutorial on them:

http://www.htmlite.com/php008.php

 

If you're using double quotes within double quotes, they need to be escaped from the current context, Such as:

print "This is a double quote: \"  <---";

 

Dollar signs have precedence in double quotes, so variable can be displayed:

$var = "foo";
print "\$var = $var"; //Will print: $var = foo

 

I'd really recommend looking up some basic PHP tutorials such as in Tizag, As you can trust from an ex-.NET programmer C is much different in its syntax than VB.

Link to comment
https://forums.phpfreaks.com/topic/199746-load-image/#findComment-1048424
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.