[文章目录]显示/隐藏

移动判断函数is_mobile(),

这个函数在module.php文件中添加,

我们可以对其修改一下,

让它涵盖更多的移动设备检测功能!

方法一:is_mobile()原函数

 
  1. function is_mobile() {  
  2.  static $is_mobile;  
  3. if ( isset($is_mobile) )  
  4.  return $is_mobile;  
  5. if ( emptyempty($_SERVER['HTTP_USER_AGENT']) ) {  
  6.  $is_mobile = false;  
  7.  } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)  
  8.  || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false  
  9.  || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false  
  10.  || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false  
  11.  || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false  
  12.  || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false  
  13.  || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {  
  14.  $is_mobile = true;  
  15.  } else {  
  16.  $is_mobile = false;  
  17.  }  
  18. return $is_mobile;  
  19. }  

方法二:is_mobile()原函数

 
  1. function is_mobile() {  
  2.  $user_agent = $_SERVER['HTTP_USER_AGENT'];  
  3.  $mobile_browser = Array(  
  4.  "mqqbrowser", //手机QQ浏览器  
  5.  "opera mobi", //手机opera  
  6.  "juc","iuc",//uc浏览器  
  7.  "fennec","ios","applewebKit/420","applewebkit/525","applewebkit/532","ipad","iphone","ipaq","ipod",  
  8.  "iemobile""windows ce",//windows phone  
  9.  "240x320","480x640","acer","android","anywhereyougo.com","asus","audio","blackberry","blazer","coolpad" ,"dopod""etouch""hitachi","htc","huawei""jbrowser""lenovo","lg","lg-","lge-","lge""mobi","moto","nokia","phone","samsung","sony","symbian","tablet","tianyu","wap","xda","xde","zte"  
  10.  );  
  11.  $is_mobile = false;  
  12.  foreach ($mobile_browser as $device) {  
  13.  if (stristr($user_agent$device)) {  
  14.  $is_mobile = true;  
  15.  break;  
  16.  }  
  17.  }  
  18.  return $is_mobile;  
  19. }  

函数的调用方法也很简单:

 
  1. <?php if(is_mobile()): ?>你的内容<?php else: ?>你的非移动设备内容<?php endif; ?>