note 82983 added to function.get-browser

From: Date: Mon, 05 May 2008 06:25:31 +0000
Subject: note 82983 added to function.get-browser
Groups: php.notes 
Request: Send a blank email to php-notes+get-139066@lists.php.net to get a copy of this message
Regexes to extract browser name and version info from a user agent string. If it doesn't find a browser name from the "subclass" list it tries the "superclass" list. <? $subclass = "MSIE,Firefox,Konqueror,Safari,Opera, Netscape,Navigator,Lynx,Amaya,Omniweb"; $superclass = "Gecko,Mozilla,Mosaic,Webkit"; $subclassregex = "(?:" . str_replace(",",")|(?:",$subclass) . ")"; $superclassregex = "(?:" . str_replace(",",")|(?:",$subclass) . ")"; $browser_name = "unrecognized"; $browser_majorversion = 0; $browser_fullversion = "0.0"; $bsuperclassmatch = FALSE; $bsubclassmatch = preg_match("/(?<browser>" . $subclassregex . ")(?:\D*)(?<majorversion>\d*) (?<subversion>(?:\.\d*)*)/i", $_SERVER['HTTP_USER_AGENT'], $matches); if (!$bsubclassmatch){ $bsuperclassmatch = preg_match("/(?<browser>" . $superclassregex . ")(?:\D*)(?<majorversion>\d*) (?<subversion>(?:\.\d*)*)/i", $_SERVER['HTTP_USER_AGENT'], $matches); } if ($bsubclassmatch||$bsuperclassmatch){ $browser_name = strtolower($matches["browser"]); $browser_majorversion = (int)$matches["majorversion"]; $browser_fullversion = $matches["majorversion"].$matches["subversion"]; if (!strcasecmp($browser_name, "Safari")){ $safarimatch = preg_match("/Version\/(?<majorversion>\d*) (?<subversion>(?:\.\d*)*)/i", $_SERVER['HTTP_USER_AGENT'], $safarimatches); if ($safarimatch){ $browser_majorversion = (int)$safarimatches["majorversion"]; $browser_fullversion = $safarimatches["majorversion"].$safarimatches["subversion"]; } } } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 24.62.180.12 ---- Manual Page -- http://www.php.net/manual/en/function.get-browser.php Edit -- https://master.php.net/note/edit/82983 Del: integrated -- https://master.php.net/note/delete/82983/integrated Del: useless -- https://master.php.net/note/delete/82983/useless Del: bad code -- https://master.php.net/note/delete/82983/bad+code Del: spam -- https://master.php.net/note/delete/82983/spam Del: non-english -- https://master.php.net/note/delete/82983/non-english Del: in docs -- https://master.php.net/note/delete/82983/in+docs Del: other reasons-- https://master.php.net/note/delete/82983 Reject -- https://master.php.net/note/reject/82983 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139066) next »