echo font color output
Question by xan
I wrote a php code that display error in red color. But somehow, this doesn’t seem to work out. Here’s my code:
<?php
...
if(!$name || !$email || !$contact || !$itemid){
//if not display an error message
echo "<span style="color: red;" /><center>Fields marked with <strong>( * ƥ</strong> are mandatory!</center></span>";
}else{...
?>
Answer by swapnesh
Do this something like that —
echo '<span style="color: red;" /><center>Fields marked with <strong>( * ƥ</strong> are mandatory!</center></span>';
Your ""
quotes are conflicting
Answer by Starx
The problem is un-escaped quotes on your PHP expression.
echo "<span style="color: red;" />...
//^ Right here
Because, Your PHP echo
statement also started with the same quote i.e "
.
Here are the different ways you can solve this:
-
Use mixed quotes
echo "<span style='color: red;' />... // Single quote in the HTML part
-
Escape the quotes
echo "<span style="color: red;" />... // Escape the quotes so that it gets treated as string rather than a modifier