HTML tag using string variable

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
ask2ksa
Forum Newbie
Posts: 2
Joined: Thu Apr 02, 2009 3:00 pm

HTML tag using string variable

Post by ask2ksa »

Hi

I am having trouble in displaying image using string variable in php as image is not displaying using below code:

Code: Select all

 
$string =  '<img width=\"100\" height=\"100\" align=\"left\" src=\"path/to/image.jpg\"  />';
echo "$string";
 
However image is displaying correctly using:

Code: Select all

 
echo "<img width=\"100\" height=\"100\" align=\"left\" src=\"path/to/image.jpg\"  />";
 
Can some please guide me about this problem.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: HTML tag using string variable

Post by Mark Baker »

No need to escape the double quotes, because the whole variable is defined within single quotes:

Code: Select all

 
$string =  '<img width="100" height="100" align="left" src="path/to/image.jpg"  />';
echo $string;
 
And no need for the quote marks when echoing a variable
ask2ksa
Forum Newbie
Posts: 2
Joined: Thu Apr 02, 2009 3:00 pm

Re: HTML tag using string variable

Post by ask2ksa »

Thanks I have checked it removing double quotes also but still same problem.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: HTML tag using string variable

Post by Mark Baker »

ask2ksa wrote:Thanks I have checked it removing double quotes also but still same problem.
So how does it appear in your HTML if you do a "View Source" in your browser?
Post Reply