PHP这样来判断是否是无线端是不是太长了
让网页在PC和无线加载不同的页面,需要一段判断代码。我的PHP判断代码:
<?php
$userAgent = $_SERVER[‘HTTP_USER_AGENT’];
$ifwap=array(‘Google Wireless Transcoder’,
‘Windows CE’,
‘WindowsCE’,
‘Symbian’,
‘Android’,
‘armv6l’,
‘armv5’,
‘Mobile’,
‘CentOS’,
‘mowser’,
‘AvantGo’,
‘Opera Mobi’,
‘J2ME/MIDP’,
‘Smartphone’,
‘Go.Web’,
‘Palm’,
‘iPAQ’,
‘iPod’,
‘iPhone’,
‘iPad’,
‘midp’,
‘iphone os’,
‘ipad’,
‘rv:1.2.3.4’,
‘ucweb’,
‘windows ce’,
‘blackberry’,
‘nokia’,
‘ios’,
‘windows mobile’
);
foreach($ifwap as $iw){
if (strpos($userAgent,$iw)){
$a=$a.’1′;
}else{
$a=$a.’0′;
}
}
if(strpos($a,’1′)){
echo “===wap===<br>”; // header(“Location: “.$w);
}else{
echo “===pc===<br>”; // header(“Location: “.$p);
}
echo $userAgent;
?>
总觉得代码是不是太长了!