note 70641 added to function.get-browser
| From: | sam at osu1 dot php dot net | Date: | Sun, 22 Oct 2006 22:09:53 +0000 |
| Subject: | note 70641 added to function.get-browser | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118985@lists.php.net to get a copy of this message | ||
I thought this function might be useful to those without access to the php.ini file (such as those
on a shared hosting system):
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!
----
Server IP: 216.194.113.175
Probable Submitter: 71.97.129.25
----
Manual Page -- http://www.php.net/manual/en/function.get-browser.php
Edit -- https://master.php.net/note/edit/70641
Del: integrated -- https://master.php.net/note/delete/70641/integrated
Del: useless -- https://master.php.net/note/delete/70641/useless
Del: bad code -- https://master.php.net/note/delete/70641/bad+code
Del: spam -- https://master.php.net/note/delete/70641/spam
Del: non-english -- https://master.php.net/note/delete/70641/non-english
Del: in docs -- https://master.php.net/note/delete/70641/in+docs
Del: other reasons-- https://master.php.net/note/delete/70641
Reject -- https://master.php.net/note/reject/70641
Search -- https://master.php.net/manage/user-notes.php