View Full Version : PHP variables and HTML

01-12-2010, 07:53 PM
Is there a way to just not let php be executed and let it stand as text in a variable? For instance this is what I'm doing:

$blah = "<li class="blah" if(empty($row['a1'])) {
echo 'style=\"display:none;\"';
if (isset($row['a1'])) {
echo ' ';
} > Blah blah blah </li>

It comes back with an error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/46/sdgsdg/htdocs/bah/blahblah.php on line 232

which is that line...

Anyone know?

01-12-2010, 08:04 PM
A bunch of different ways to do it ... this is just one of many ...

echo "<li class=\"blah\" style=\"$style\" > blah blah blah </li>";

01-12-2010, 08:41 PM
Heredoc (http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) perhaps?
You could also use single quotes around the text, or escape the " inside the text with a \

01-12-2010, 10:10 PM

Thanks! I just wasn't thinking straight for some reason with putting if statements in variables ha. You brought simplicity to my attention and helped me sincerely. Appreciate it!