note 70641 deleted from function.get-browser by cmb

From: Date: Sun, 23 Feb 2020 08:55:35 +0000
Subject: note 70641 deleted from function.get-browser by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-214193@lists.php.net to get a copy of this message
Note Submitter: sam ---- I thought this function might be useful to those without access to the php.ini file (such as those on a shared hosting system): <?php function php_get_browser($agent = NULL){ $agent=$agent?$agent:$_SERVER['HTTP_USER_AGENT']; $yu=array(); $q_s=array("#\.#","#\*#","#\?#"); $q_r=array("\.",".*",".?"); $brows=parse_ini_file("php_browscap.ini",true); foreach($brows as $k=>$t){ if(fnmatch($k,$agent)){ $yu['browser_name_pattern']=$k; $pat=preg_replace($q_s,$q_r,$k); $yu['browser_name_regex']=strtolower("^$pat$"); foreach($brows as $g=>$r){ if($t['Parent']==$g){ foreach($brows as $a=>$b){ if($r['Parent']==$a){ $yu=array_merge($yu,$b,$r,$t); foreach($yu as $d=>$z){ $l=strtolower($d); $hu[$l]=$z; } } } } } break; } } return $hu; } ?> define the location of php_browscap.ini wherever you want always returns an array, same functionality as get_browser(NULL,true) Hope someone finds it useful!

« previous php.notes (#214193) next »