Try this:
Code:
if (strstr($HTTP_USER_AGENT,"MSIE")){
$browser = "IE";
preg_match('/MSIE\s+(\d+[\d\.]*)[\s,;]*/', $HTTP_USER_AGENT, $browser_version);
echo($browser_version[1]);
}
elseif (strstr($HTTP_USER_AGENT,"Netscape")){
$browser = "NN";
preg_match('/Netscape\s+(\d+[\d\.]*)[\s,;]*/', $HTTP_USER_AGENT, $browser_version);
echo($browser_version[1]);
}
elseif (strstr($HTTP_USER_AGENT,"Lynx")){
$browser = "Lynx";
preg_match('/Lynx\s+(\d+[\d\.]*)[\s,;]*/', $HTTP_USER_AGENT, $browser_version);
echo($browser_version[1]);
}
elseif ($browser != "IE" || "NN" || "Lynx"){
$browser = "Unknown";
It works like this:
Code:
/ begin the search
MSIE\s+ find the first occurance of "MSIE" that is followed by whitespace
( begin saving the data found here
\d+ match at least one digit
[\d\.]* match 0 or more digits and periods
) stop saving data matched
[\s,;] match whitespace, commas and semicolons
If that description does you any good at all I'll be amazed. Like I said, it took me three chapters and that was just the basics
However, the code might just work.
Bookmarks