Mobile Detect是检测移动设备(包括平板电脑)一个轻量级的PHP类。它使用的User-Agent字符串与特定的HTTP标头组合,以检测移动环境。
您可以考虑这个脚本是RESS(与服务器端组件响应网页设计)的一部分。通过阅读这些文章,你可以学到更多关于响应式的知识:
Mobile Detect下载地址:https://github.com/serbanghita/Mobile-Detect/archive/2.8.22.zip
Mobile Detect演示地址:http://demo.mobiledetect.net/
下面是Mobile Detect使用方法示例:
// Include and instantiate the class.
require_once \'Mobile_Detect.php\';
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
}
// Any tablet device.
if( $detect->isTablet() ){
}
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
}
// Check for a specific platform with the help of the magic methods:
if( $detect->isiOS() ){
}
if( $detect->isAndroidOS() ){
}
// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->is(\'Chrome\')
$detect->is(\'iOS\')
$detect->is(\'UC Browser\')
// [...]
// Batch mode using setUserAgent():
$userAgents = array(
\'Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19\',
\'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103\',
// [...]
);
foreach($userAgents as $userAgent){
$detect->setUserAgent($userAgent);
$isMobile = $detect->isMobile();
$isTablet = $detect->isTablet();
// Use the force however you want.
}
// Get the version() of components.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->version(\'iPad\'); // 4.3 (float)
$detect->version(\'iPhone\') // 3.1 (float)
$detect->version(\'Android\'); // 2.1 (float)
$detect->version(\'Opera Mini\'); // 5.0 (float)
// [...] 继续阅读与本文标签相同的文章
上一篇 :
为什么开发人员对低代码好感度不高?
-
中国客车“抢眼”世界客车博览会
2026-05-14栏目: 教程
-
充分利用系统磁盘空间,Windows 7操作系统如何创建压缩文件夹
2026-05-14栏目: 教程
-
iPhone11系列性能测试:碾压华为麒麟990,性能超越它两倍!
2026-05-14栏目: 教程
-
手机导航是怎样判断路况的?不仅是通过卫星,这几个原因使导航更智能
2026-05-14栏目: 教程
-
手机信号突然从“4G”变成“E”,是什么意思?客服给出答案
2026-05-14栏目: 教程
