Home > OS >  how do I echo a website-linked photo in php?
how do I echo a website-linked photo in php?

Time:03-29

I've looked at every other example of the problem I'm having and none have covered how to do an actual website URL link within an echoed image in PHP. I'm sure I have to use an escape character of some sort but I'm not sure where or which one. here is my code

<?php
echo "<a href=\'https://validator.w3.org/nu/"><img src="HTMLVALIDATIONIMAGE.png"  /></a>";
echo "<a href=\'https://validator.w3.org/nu/"><img src="CSSVALIDATIONIMAGE.png"  /></a>"";
echo "<b>Last Modified:</b> " . date('F d Y h:i A', filemtime($_SERVER['SCRIPT_FILENAME']));
?>

CodePudding user response:

Use single quotes around the HTML attributes when you're using double quotes around the PHP string. Then you don't need to escape anything.

echo "<a href='https://validator.w3.org/nu/'><img src='HTMLVALIDATIONIMAGE.png'></a>";

CodePudding user response:

You, of course can omit the quotes in HTML5 :

<?php
echo "<a href=https://validator.w3.org/nu/><img src=HTMLVALIDATIONIMAGE.png></a>";
echo "<a href=https://validator.w3.org/nu/><img src=CSSVALIDATIONIMAGE.png ></a>";
echo "<b>Last Modified:</b> " . date('F d Y h:i A', filemtime($_SERVER['SCRIPT_FILENAME']));

CodePudding user response:

Try this

Making your code more readable.

<?php
echo "<a href='https://validator.w3.org/nu/'><img src='HTMLVALIDATIONIMAGE.png'  /></a>";
echo "<a href='https://validator.w3.org/nu/'><img src='CSSVALIDATIONIMAGE.png'  /></a>";
echo "<b>Last Modified:</b> " . date('F d Y h:i A', filemtime($_SERVER['SCRIPT_FILENAME']));
?>
  • Related