zemax Posted September 30, 2007 Share Posted September 30, 2007 I just started learning PHP and I am trying to read form data and then display it using echo. Here is what I am using echo $row["title"]; If I want to display it in let say red color how can I do that? I have trued echo "<font color="#660000">$row["title"]</font>; but it gives error. Can someone please help me. Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/ Share on other sites More sharing options...
sKunKbad Posted September 30, 2007 Share Posted September 30, 2007 echo "<font color='#660000'>$row['title']</font>"; paste your error if this doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/#findComment-358234 Share on other sites More sharing options...
jbingman Posted September 30, 2007 Share Posted September 30, 2007 You need to use backslashes in the echo statement so it looks like this: echo "<font color=\"#660000\">$row[\"title\"]</font>"; or change the double quotations inside the statement to single quotations: echo "<font color='#660000'>$row['title']</font>"; Does that fix it? Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/#findComment-358235 Share on other sites More sharing options...
zemax Posted September 30, 2007 Author Share Posted September 30, 2007 echo "<font color='#660000'>$row['title']</font>"; paste your error if this doesn't work When I try this I get following error PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,expecting T_STRING or T_VARIABLE or T_NUM_STRING Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/#findComment-358238 Share on other sites More sharing options...
zemax Posted September 30, 2007 Author Share Posted September 30, 2007 echo "<font color='#660000'>$row['title']</font>"; paste your error if this doesn't work When I try this I get following error PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,expecting T_STRING or T_VARIABLE or T_NUM_STRING I am getting same error i.e. PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,expecting T_STRING or T_VARIABLE or T_NUM_STRING Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/#findComment-358239 Share on other sites More sharing options...
d.shankar Posted September 30, 2007 Share Posted September 30, 2007 try this <?php $var="color"; echo "<font color='#660000'>$var</font>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/#findComment-358243 Share on other sites More sharing options...
sKunKbad Posted September 30, 2007 Share Posted September 30, 2007 This works, I checked it: <?php $row['title'] = 'whatever'; echo "<font color='#660000'>".$row['title']."</font>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/#findComment-358245 Share on other sites More sharing options...
zemax Posted September 30, 2007 Author Share Posted September 30, 2007 This works, I checked it: <?php $row['title'] = 'whatever'; echo "<font color='#660000'>".$row['title']."</font>"; ?> Thanks it worked. Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/#findComment-358246 Share on other sites More sharing options...
btherl Posted September 30, 2007 Share Posted September 30, 2007 Here's another option (just to confuse you) echo "<font color='#660000'>{$row['title']}</font>"; The {} protects the variable inside so it is interpreted correctly. Quote Link to comment https://forums.phpfreaks.com/topic/71220-solved-color-echo/#findComment-358247 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.