...

View Full Version : PHP variables and HTML



Joemoemofo
01-12-2010, 06: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?

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




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

JAY6390
01-12-2010, 07: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 \

Joemoemofo
01-12-2010, 09:10 PM
@mlseim

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!

@jay

thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum