PHP code from head section shows in html

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.

I can’t see any problem with this code. Are you sure PHP is being parsed? Are you using a .html or .php extension?

I just found the problem. I was attempting to add the code to the head section of asp.net master page. I’m a php newbie who just found out that php is incompatible with the asp.net framework.

Sponsor our Newsletter | Privacy Policy | Terms of Service