Shoutbox

formatting web browsers - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: formatting web browsers (/showthread.php?tid=74256)

formatting web browsers by Nathan on 05-08-2007 at 06:11 PM

Ok,
Well i've been confused on how to format browsers so they display as Firefox or
IE6 using php. I've resorted to str_ireplace temporarily but i need to know if there's an eaiser way using arrays or whatever or if theres a function to do this with.

thanks guys,
Nathna


RE: formatting web browsers by Baggins on 05-08-2007 at 07:05 PM

If you mean detect the browser type I would use RegExp on $_SERVER['HTTP_USER_AGENT']

[offtopic]
Nice to meet you Nathna:)


RE: formatting web browsers by Nathan on 05-08-2007 at 08:32 PM

Could you give me an example please?

Cheers.


RE: formatting web browsers by absorbation on 05-08-2007 at 08:33 PM

What are you trying to do Nath? Your post is very confusing :P


RE: formatting web browsers by user35870 on 05-08-2007 at 08:33 PM

I'm not sure if this is the best way to do it or is what you mean, but here go's:

code:
<?php
$browser = $_SERVER['HTTP_USER_AGENT'];

if (preg_match("/firefox/i", "$browser")) {
$result = "Mozilla Firefox";
}
elseif (preg_match("/ie/i", "$browser")) {
$result = "Internet Explorer";
}
elseif (preg_match("/opera/i", "$browser")) {
$result = "Opera";
}
else {
$result = "Unknown";
}
echo "<strong>$result</strong>";
?>


(note: I've only done some examples, you can expand it for others such as Netscape if you want.)
RE: formatting web browsers by Nathan on 05-08-2007 at 08:34 PM

That's exactly what I want Chris <3

Thanks :)


RE: formatting web browsers by absorbation on 05-08-2007 at 08:38 PM

Here is a small script I use from Hmaster:

code:
if (preg_match("/Firefox/", $agent))
    {
        $agent = "Firefox";
    }
   
    elseif (preg_match("/Safari/", $agent))
    {
        $agent = "Safari";
    }
   
    elseif (preg_match("/Opera/", $agent))
    {
        $agent = "Opera";
    }
   
    elseif (preg_match("/Netscape/", $agent))
    {
        $agent = "Netscape";
    }
   
    elseif (preg_match("/Konqueror/", $agent))
    {
        $agent = "Konqueror";
    }
   
    elseif (preg_match("/Camino/", $agent))
    {
        $agent = "Camino";
    }
   
    elseif (preg_match("/MSIE/", $agent))
    {
        $agent = "Internet Explorer";
    }
   
    elseif (preg_match("/Mac/", $agent))
    {
        $agent = "Macintosh";
    }
   
    elseif (preg_match("/Mozilla/", $agent))
    {
        $agent = "Mozilla";
    }
   
    else
    {
        $agent = "Unknown Browser";
    }

$agent represents the variable of the user's browser. Add the value yourself ;).

RE: formatting web browsers by FineWolf on 05-08-2007 at 10:19 PM

Or, if you need advanced browser detection:
http://apptools.com/phptools/browser/