PHP判断是安卓还是苹果还是电脑,之前发的方法没这个全面,建议使用这个
function strexists($string, $find) { return !(strpos($string, $find) === false); }
function deep_in_array($value, $array) {
foreach($array as $item) {
if(!is_array($item)) {
if (strpos($value, $item) !== false) {
return true;
} else { continue; } }
if(in_array($value, $item)) {
return true;
} else if(deep_in_array($value, $item)) {
return true;
}
} return false; }
function mobile() {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
$ualist = array('android', 'midp', 'nokia', 'mobile', 'iphone', 'ipod', 'blackberry', 'windows phone');
if((deep_in_array($useragent, $ualist) || strexists($_SERVER['HTTP_ACCEPT'], "VND.WAP") || strexists($_SERVER['HTTP_VIA'],"wap")))
if(strpos($useragent,'iphone')!==false||strpos($useragent,'ipod')!==false) return '苹果'; else return '安卓';
else
return '电脑'; }
评论
发表评论: