PHP判断是否为手机客户端
生活随笔
收集整理的這篇文章主要介紹了
PHP判断是否为手机客户端
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/** * 判斷是否是通過手機訪問 * @return bool 是否是移動設備 */ public function isMobile() { //判斷手機發送的客戶端標志 if(isset($_SERVER['HTTP_USER_AGENT'])) { $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); $clientkeywords = array( 'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-' ,'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'opera mobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile' ); // 從HTTP_USER_AGENT中查找手機瀏覽器的關鍵字 if(preg_match("/(".implode('|',$clientkeywords).")/i",$userAgent)&&strpos($userAgent,'ipad') === false) { return true; } } return false; } 轉載地址:http://blog.csdn.net/andy1219111/article/details/27543391
總結
以上是生活随笔為你收集整理的PHP判断是否为手机客户端的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP部分字符串函数汇总
- 下一篇: PHP中文乱码的常见解决方法总结