Page 1 of 1

HTML tag using string variable

Posted: Thu Apr 02, 2009 3:10 pm
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.

Re: HTML tag using string variable

Posted: Thu Apr 02, 2009 3:20 pm
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

Re: HTML tag using string variable

Posted: Thu Apr 02, 2009 3:32 pm
by ask2ksa
Thanks I have checked it removing double quotes also but still same problem.

Re: HTML tag using string variable

Posted: Thu Apr 02, 2009 3:51 pm
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?