Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. function browser_info($agent=null) {
  2.   // Declare known browsers to look for
  3.   $known = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape',
  4.     'konqueror', 'gecko');
  5.  
  6.   // Clean up agent and build regex that matches phrases for known browsers
  7.   // (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor
  8.   // version numbers.  E.g. "2.0.0.6" is parsed as simply "2.0"
  9.   $agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']);
  10.   $pattern = '#(?<browser>' . join('|', $known) .
  11.     ')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#';
  12.  
  13.   // Find all phrases (or return empty array if none found)
  14.   if (!preg_match_all($pattern, $agent, $matches)) return array();
  15.  
  16.   // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
  17.   // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
  18.   // in the UA).  That's usually the most correct.
  19.   $i = count($matches['browser'])-1;
  20.   return array($matches['browser'][$i] => $matches['version'][$i]);
  21. }




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2017