I would like to echo the following giving it a CSS style
echo $result['definition'];
I tried this (without the space before definition. i wrote the space because otherwise yahoo for some reason cut the line of code):
echo "<span class=\"text5\">$result[' definition']</span><p>"; but it does not work
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
Copyright © 2024 VQUIX.COM - All rights reserved.
Answers & Comments
Verified answer
Hi try this:
echo "<span class='text5\'>".$result[' definition']."</span><p>";
you have been putting a php "variable" within the print string.
You must separate all php variables from a string in "" like this:
<?php
$name = "john";
echo "My name is ".$name;
?>
and not like:
<?php
$name = "john";
echo "My name is $name";
?>
Php Print Class
1) $nav_bar = "<div id=nav> <a href=index.php><div class=<?php if($page == index.php){echo active}else{echo button}?>>Home</div></a> is all part of $nav_bar. You have to close the quote. $nav_bar = "<div id=nav> <a href=index.php><div class="; <?php if($page == index.php){echo active;}else{echo button;}?> $nav_bar .- ">Home</div></a> etc. 2) echo "$nav_bar" will echo the contents of $nav_bar (echo '$nav_bar' will echo the string $nav_bar) but it's a waste of processing power, since you aren't echoing any literals. echo $nav_bar will give you the same output without making the PHP parser figure out ewhat's inside the quotes. For a small site that gets a few hits, it makes very little difference. On a very busy site a few dozen uses of unneeded quotes could make the difference between the site working and the site crashing.
Instead of this :
echo "<span class=\"text5\">
$result[' definition']
</span><p>";
try this
echo "<span class=\"text5\">".
$result['definition'].
"</span><p>";
or better
<span class="text5">
<?php echo $result['definition'] ?>
</span>
avoid(as long as you can) writing HTML code with PHP, use it only for content