
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.72 KB | hits: 12 | expires: Never
stop at the first string matched using strpos() in PHP
private $arrAgent = array(
'sony',
'symbian',
'nokia',
'samsung',
'mobile',
'windows ce',
'blackberry',
'ericsson',
'danger',
'palm',
'series60',
'palmsource',
'pocketpc',
'smartphone',
'vodafone',
'iphone',
'ipad',
'android'
);
private function detectMobileAgent() {
if ($this->MobileDevice === false) {
foreach ($this->arrAgent as $key => $value) {
if (strpos(Server::userAgent(), $value) !== false) {
$this->MobileDevice = true;
// echo $value;
break;
}
}
}
}
mozilla/5.0 (ipad; u; cpu os 4_3_2 like mac os x; en-us) applewebkit/533.17.9 (khtml, like gecko) version/5.0.2 mobile/8h7 safari/6533.18.5
$arrAgent = array(
'sony',
'symbian',
'nokia',
'samsung',
'mobile',
'windows ce',
'blackberry',
'ericsson',
'danger',
'palm',
'series60',
'palmsource',
'pocketpc',
'smartphone',
'vodafone',
'iphone',
'android',
'ipad'
);
$agent = 'mozilla/5.0 (ipad; u; cpu os 4_3_2 like mac os x; en-us) applewebkit/533.17.9 (khtml, like gecko) version/5.0.2 mobile/8h7 safari/6533.18.5';
$pattern = '/((' . implode(')|(', $arrAgent) . '))/';
$found = preg_match($pattern, $agent, $matches);
if (!$found) {
print 'not a mobile device';
exit;
}
print 'device: ' . $matches[0];
if ($this->MobileDevice === false && strpos(Server::userAgent(), 'ipad') === false) {
foreach ($this->arrAgent as $key => $value) {
if (strpos(Server::userAgent(), $value) !== false) {
$this->MobileDevice = true;
// echo $value;
break;
}
}
}