Aug.19

Detecting Android, iPhone, iPod, iPad and BlackBerry browser with PHP

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$ua_checker = array(
  'android'=>preg_match('/android/', $ua),
  'iphone'=>preg_match('/iphone|ipod|ipad/', $ua),
  'blackberry'=>preg_match('/blackberry/', $ua)
);
if ($ua_checker['android']) {
  // up to you
}
else if ($ua_checker['iphone']) {
  // up to you
}
else if ($ua_checker['blackberry']) {
  // up to you
}
Web Programming