Jump to content
Updating IPB tonight Read more... ×

Archived

This topic is now archived and is closed to further replies.

realjumper

Reading cookies

Recommended Posts

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 :-)

Share this post


Link to post
Share on other sites
try this ok for an idear ok.

[code]

<?

$name="redarrow";

$result=str_replace("r","<font color='red'>r</font>",$name);



echo $result;

?>

[/code]

Share this post


Link to post
Share on other sites
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 :-)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.