I’m using PHP code in the head section of my html page to select a css file based on the browser the html page is being viewed in.
Here is my code:
[php]
if (preg_match(’/MSIE/i’, $_SERVER[“HTTP_USER_AGENT”])) {
echo ‘’;
}
else if (preg_match(’/Firefox/i’, $_SERVER[“HTTP_USER_AGENT”])) {
echo ‘’;
}
else if (preg_match(’/Chrome/i’, $_SERVER[“HTTP_USER_AGENT”])) {
echo ‘’;
}
else if (preg_match(’/Safari/i’, $_SERVER[“HTTP_USER_AGENT”])) {
echo ‘’;
}
[/php]
The php code works and in the IE browser none of the php code shows in the page. In Firefox, Chrome, and Safari, the php code works by selecting the correct browser, but it shows the following section of code in the top of page’s markup:
[php]’; } else if (preg_match(’/Firefox/i’, $_SERVER[“HTTP_USER_AGENT”])) { echo ‘’; } else if (preg_match(’/Chrome/i’, $_SERVER[“HTTP_USER_AGENT”])) { echo ‘’; } else if (preg_match(’/Safari/i’, $_SERVER[“HTTP_USER_AGENT”])) { echo ‘’; } ?>[/php]
What is wrong with the syntax of my code for it to show in header of Firefox, Chrome, and Safari? I don’t see any syntax errors.