ARRGG!!! Ok, I am learning how to code in PHP from a book called "PHP essentials". I was doing pretty well in the book until I reached this one lesson with having a stylesheet (CSS) code for each browser platform. So if someone goes to the .html page (with php code under the <HEAD> tag) with lets say Internet Explorer, the php code is supposed to output CSS stylesheet coding that works well with Internet explorer. And of course, if someone with netscape goes to the page, the page outputs CSS code that works well with Netscape. Oh yeah, and to call out this PHP code with an echo() function, I'm calling out an external CSS command that calls in the code for the browser.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>MY PAGE</TITLE>
<?php
$browser_type = getenv("HTTP_USER_AGENT");
if (preg_match("/MSIE/i", "$browser_type")) {
echo "<LINK REL=stylesheet HREF=msie_stylesheet.css>";
} else if (preg_match("/Mozilla/i", "$browser_type")) {
echo "<LINK REL=stylesheet HREF=ns_stylesheet.css>";
}
?>
</HEAD>
<BODY>
<A HREF="HTTP://WWW.HTML4ME.COM">GO TO HTML4ME.COM BY CLICKING ON THIS LINK</A>
</BODY>
</HTML>
Is there anything wrong with my code? You can see this code in action at: >> http://www.html4me.com/php9/stylish1.html . I also put the .css files in the same sub directory folder, so I didn't mess up on that.
Also, the weird thing is that if you look at that page with Netscape 6, it WORKS, but some PHP code is sprayed onto the page (which isn't supposed to happen). And it doesn't work in IE....
Oh yeah, and I HAD quotes in the link stylesheet coding, but I took them out because it was screwing things up. ( I had the \'s to outline the quotes so I wouldn't get any parsing errors, and I didn't get any errors, but it also didn't work...)
Thanks all!
Gregory C.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>MY PAGE</TITLE>
<?php
$browser_type = getenv("HTTP_USER_AGENT");
if (preg_match("/MSIE/i", "$browser_type")) {
echo "<LINK REL=stylesheet HREF=msie_stylesheet.css>";
} else if (preg_match("/Mozilla/i", "$browser_type")) {
echo "<LINK REL=stylesheet HREF=ns_stylesheet.css>";
}
?>
</HEAD>
<BODY>
<A HREF="HTTP://WWW.HTML4ME.COM">GO TO HTML4ME.COM BY CLICKING ON THIS LINK</A>
</BODY>
</HTML>
Is there anything wrong with my code? You can see this code in action at: >> http://www.html4me.com/php9/stylish1.html . I also put the .css files in the same sub directory folder, so I didn't mess up on that.
Also, the weird thing is that if you look at that page with Netscape 6, it WORKS, but some PHP code is sprayed onto the page (which isn't supposed to happen). And it doesn't work in IE....
Oh yeah, and I HAD quotes in the link stylesheet coding, but I took them out because it was screwing things up. ( I had the \'s to outline the quotes so I wouldn't get any parsing errors, and I didn't get any errors, but it also didn't work...)
Thanks all!
Gregory C.
Comment