Skip to content

Instantly share code, notes, and snippets.

@libo1106
Last active December 29, 2015 08:29
Show Gist options
  • Save libo1106/7644139 to your computer and use it in GitHub Desktop.
Save libo1106/7644139 to your computer and use it in GitHub Desktop.
UserAgent 匹配Android和iOS,并获得对于的版本号
<?php
/*
* UserAgent 匹配Android和iOS,并获得对于的版本号
*/
function match($ua){
if( strpos($ua, 'Android')){// 匹配 Android
preg_match('/(Android)[\/ ]([\d._]+)/', $ua, $match);
}else if( strpos($ua, 'Mobile')){// 匹配 iOS
preg_match('/(OS) ([\d._]+)/', $ua, $match);
}else{
$match[1] = 'unknown';
$match[2] = 'unknown';
}
return $match;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment