Re: parsing useragent string without get_browser

From: Date: Thu, 25 Aug 2005 14:45:40 +0000
Subject: Re: parsing useragent string without get_browser
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-221357@lists.php.net to get a copy of this message
The problem is I haven't seen any examples of this in php. The best I have come up with is the following. I know the code is pants, but it works. I am sure people out there can think of a better way of doing it- $ua = $logInfo[useragent]; if ( ereg("Firefox/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("MSIE [0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("Bloglines/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("Amfibibot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("msnbot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("Googlebot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("Safari/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("Konqueror/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("Netscape/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if ( ereg("Thunderbird/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua, $array)) {$browser = $array[0];} if (strpos($ua, "Web RSS Reader")!== FALSE) {$browser = "Web RSS Reader";} if (strpos($ua, "BDFetch")!== FALSE) {$browser = "BDFetch";} if (strpos($ua, "www.almaden.ibm.com/cs/crawler")!== FALSE) {$browser = "Web Fountain";} if (strpos($ua, "sohu-search")!== FALSE) {$browser = "Sohu Search";} if (strpos($ua, "Yahoo! Slurp")!== FALSE) {$browser = "Yahoo! Slurp";} if (strpos($ua, "Windows NT 5.1")) {$platform = "Windows XP";} elseif (strpos($ua, "Windows NT 5.0")) {$platform = "Windows 2000";} elseif (strpos($ua, "Windows 98") OR strpos($ua, "Win98")) {$platform = "Windows 98";} elseif (strpos($ua, "Windows 95") OR strpos($ua, "Win95")) {$platform = "Windows 95";} elseif (strpos($ua, "Win16") OR strpos($ua, "Windows 3.1")) {$platform = "Windows 3.1";} elseif (strpos($ua, "Mac OS X")) {$platform = "Mac OSX";} elseif (strpos($ua, "Linux")) {$platform = "Linux";}

« previous php.general (#221357) next »