Forum Moderators: coopster

Message Too Old, No Replies

Alternate CSS Script

         

Menekali

4:25 am on Mar 11, 2005 (gmt 0)

10+ Year Member



I have this code:

<?
$ie=false;
$ie += substr_count($HTTP_USER_AGENT,"MSIE");

if($ie) {
echo "<LINK REL=StyleSheet HREF=\"ie.css\" TYPE=\"text/css\">";
}
else {
echo "<LINK REL=StyleSheet HREF=\"ff.css\" TYPE=\"text/css\">";
}
?>

Now it seems to load the ie.css if it detects the browser as Internet Explorer, but it fails to load up the ff.css if the browser ISNT Internet explorer. Am i doing something wrong here? Thanks!

badone

10:28 am on Mar 11, 2005 (gmt 0)

10+ Year Member



Ahh.... grasshopper.

You're mixing types.

substr_count() returns an integer which is not necessarily an exact match for a boolen type such as true/false.

try;

if( $ie!= 0 ) or if( $ie > 0 )

If you want to test if $ie IS zero use;
if( $ie === 0 ) // exact match

HTH,
BAD

sifredi

11:36 am on Mar 11, 2005 (gmt 0)

10+ Year Member



How about:

<?
$css = preg_match("/MSIE/",$HTTP_USER_AGENT)?"ie.css":"ff.css";
echo "<link rel=stylesheet href=\"$css\" type=\"text/css\">";
?>