realjumper Posted July 20, 2006 Share Posted July 20, 2006 Hi,I set a cookie according to an 'if' 'else' situation something like this...[code]if ($cpd_id == $doo){setcookie ("answer", "Yes - $row2[compound] is the correct answer");}else{setcookie ("answer", "Sorry - $row2[compound] was the correct answer");}echo $_COOKIE["answer"];[/code]What I would like to do is colour the text according to the answer.....red for a wrong answer, green a correct answer.The variable $row2[compound] will always be different, so is there a way to detect a single word in the cookie, say, 'Yes' and then colour the answer in a green font? Very crudely, this is what I would like to do if it's possible....[code]if ($_COOKIE["answer"] contains 'Yes' as the first 3 characters) { echo <p style='color:green'>$_COOKIE["answer"]</p>; }else{ echo <p style='color:red'>$_COOKIE["answer"]</p>; }[/code]Is something like this possible?Thanks :-) Quote Link to comment https://forums.phpfreaks.com/topic/15101-reading-cookies/ Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 try this ok for an idear ok.[code]<?$name="redarrow";$result=str_replace("r","<font color='red'>r</font>",$name);echo $result;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15101-reading-cookies/#findComment-60829 Share on other sites More sharing options...
realjumper Posted July 20, 2006 Author Share Posted July 20, 2006 Yep, that will do the trick! Thanks a lot :-)Neil Quote Link to comment https://forums.phpfreaks.com/topic/15101-reading-cookies/#findComment-60830 Share on other sites More sharing options...
realjumper Posted July 20, 2006 Author Share Posted July 20, 2006 This is the end result, which works prefectly :-)[code]$response=$_COOKIE["answer"];$answ = explode(" ", $response);if ($answ[0] == 'Sorry'){echo "<font color='red'>$response</font>";}else {echo "<font color='green'>$response</font>";}[/code]Thanks :-) Quote Link to comment https://forums.phpfreaks.com/topic/15101-reading-cookies/#findComment-60835 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.