img tag in php file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thosecars82
Forum Commoner
Posts: 94
Joined: Thu Apr 03, 2008 6:31 am
Location: Arganda, Madrid
Contact:

img tag in php file

Post by thosecars82 »

Hello there
I am writing to ask you a really simple thing. It has to do with the img tag. I have been using php+mysql+apache so far. However, I do not know why when I use the img tag in the code below, I cannot see any image at all on my browser. What I see instead is the alt name which is "wewe" in this particular case according to the code below.

file.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<img src="estilos/images/spanishflag.gif" alt="wewe" />
</body>
</html>


On the other hand if I rename this file so that it is file.html instead of file.php, then browsing the file file.html will let me see the image.
So for me it is quite weird: I just can see the image when the extension of the file is html because if it is .php then I just see the name specified in the alt parameter of img.
Since I have been stuck with this stupid thing for a while, my brain is quite tired right now. Moreover, there might be an easy answer to my doubt which I have not found yet. Anyways, I would appreciate your suggestions since I am stuck with this.
Thanks in advance.
thosecars82
Forum Commoner
Posts: 94
Joined: Thu Apr 03, 2008 6:31 am
Location: Arganda, Madrid
Contact:

Re: img tag in php file

Post by thosecars82 »

solution:
<?php
echo "<img src="estilos/images/spanishflag.gif" alt="wewe" />"
?>
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: img tag in php file

Post by lafever »

You'll want to use ' instead of quotes to open and close the echo otherwise you'll have to add a backslash (\) before each quote if you open it with quotes

Code: Select all

 
<?php
echo '<img src="estilos/images/spanishflag.gif" alt="wewe" />';
?>
 
or

Code: Select all

 
<?php
echo "<img src=\"estilos/images/spanishflag.gif\" alt=\"wewe\" />";
?>
 
Post Reply