I am working on an example from a php book and am getting an error on line 8 with this code
<?php
$agent = getenv("HTTP_USER_AGENT");
if (preg_match("/MSIE/i", "$agent"));
{
$result = "You are using Microsoft Internet Explorer";
}
else if (preg_match("/Mozilla/i", "$agent"));
{
$result = "You are using Mozilla firefox";
}
else {$result = "you are using $agent"; }
echo $result;
?>
Try:
Two things:
You had a semi-colon at the end of your if clauses. That means the subsequent opening brace was a local block that is always executed. That caused a problem because later you had an
elsestatement that wasn’t attached to anifstatement; andDoing
"$agent"is unnecessary and not recommended. Simply pass in$agent.