Last active
December 29, 2015 08:29
-
-
Save libo1106/7644139 to your computer and use it in GitHub Desktop.
UserAgent 匹配Android和iOS,并获得对于的版本号
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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