View Full Version : Setting HTML Code as a Variable

01-29-2003, 08:50 PM
I am simply trying to set a variable which contains HTML code.

To use
$var = "image"
is fine but when you get to
$var = "<img scr="image.gif" alt="image">"
etc. etc. I start getting errors.

Is there a special way to set a large HTML sement to a variable?

01-29-2003, 09:01 PM
Your problem there is that you haven't escaped the quotes. There are two ways to do it:
$var = "<img scr=\"image.gif\" alt=\"image\">"
$var = "<img scr='image.gif' alt='image'>"

01-30-2003, 12:37 AM
Great, cheers, shoulda known that one :rolleyes:

Thanks :D

01-30-2003, 01:01 AM
...3 ways :D

$var = '<img scr="image.gif" alt="image">';

02-02-2003, 05:15 AM

Check http://www.php.net/manual/en/language.types.string.php for Heredoc string quoting.

It is useful to store large quantities of HTML in a variable without worrying about escaping quotes etc.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum