Here is a function which detects mobile brand,
other wapmasters are welcome to improve this function and post here their works.
usage:
output:
other wapmasters are welcome to improve this function and post here their works.
PHP Code:
function brand_detect($user_agent)
{
$brands = array(
array(
'id' => '100',
'brand' => 'Nokia',
'check' => array('nokia')
),
array(
'id' => '200',
'brand' => 'SonyEricsson',
'check' => array('sonyericsson')
),
array(
'id' => '300',
'brand' => 'Samsung',
'check' => array('samsung','sec-','sam-','sgh-')
),
array(
'id' => '400',
'brand' => 'LG',
'check' => array('lg/','lg-')
),
array(
'id' => '500',
'brand' => 'Motorola',
'check' => array('mot-','moto')
),
array(
'id' => '600',
'brand' => 'RIM BlackBerry',
'check' => array('blackberry')
),
array(
'id' => '700',
'brand' => 'HTC',
'check' => array('htc')
),
array(
'id' => '800',
'brand' => 'Apple',
'check' => array('ipod','iphone','ipad')
),
array(
'id' => '900',
'brand' => 'Sagem',
'check' => array('sagem')
),
array(
'id' => '1010',
'brand' => 'Bird',
'check' => array('bird')
),
array(
'id' => '1020',
'brand' => 'Zen',
'check' => array('z77')
),
array(
'id' => '1030',
'brand' => 'Haier',
'check' => array('htil')
),
array(
'id' => '1040',
'brand' => 'Micromax',
'check' => array('micromax')
),
array(
'id' => '1050',
'brand' => 'Spice',
'check' => array('spice')
),
array(
'id' => '1060',
'brand' => 'ZTE',
'check' => array('zte-')
),
array(
'id' => '1070',
'brand' => 'Huawei',
'check' => array('huawei')
),
array(
'id' => '1080',
'brand' => 'Fly',
'check' => array('fly-')
),
array(
'id' => '1090',
'brand' => 'Nexian',
'check' => array('nexian')
),
array(
'id' => '9090',
'brand' => 'RT',
'check' => array('rt')
)
/*array(
'id' => '800',
'brand' => 'Apple Ipod Touch',
'check' => array('ipod')
),
array(
'id' => '810',
'brand' => 'Apple Iphone',
'check' => array('iphone')
),
array(
'id' => '820',
'brand' => 'Apple Ipad',
'check' => array('ipad')
)*/
);
foreach($brands as $brand)
{
foreach($brand['check'] as $check)
{
if(stristr($user_agent,$check))
{
$found = true;
break;
}
}
if($found) break;
}
return $brand;
}
PHP Code:
$ua = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3';
print_r(brand_detect($ua));
Code:
Array ( [id] => 800 [brand] => Apple [check] => Array ( [0] => ipod [1] => iphone [2] => ipad ) )
Comment