分享

检测移动设备(手机)的 PHP 类库

 昵称3884271 2014-01-09
Mobile_Detect 是一个轻量级的开源移动设备(手机)检测的 PHP Class,它使用 User-Agent 中的字符串,并结合 HTTP Header,来检测移动设备环境。这个设备检测的 PHP 类库最强大的地方是,它有一个非常完整的库,可以检测出所用的设备类型(包括操作类型,以及手机品牌等都能检测)和浏览器的详细信息。
标签: PHP

代码片段(1) [全屏查看所有代码]

1. [代码][PHP]代码     跳至 [1] [全屏预览]

01//使用实例
02 
03include 'Mobile_Detect.php';
04$detect = new Mobile_Detect();
05 
06// Check for any mobile device.
07if ($detect->isMobile())
08 
09// Check for any tablet.
10if($detect->isTablet())
11 
12// Check for any mobile device, excluding tablets.
13if ($detect->isMobile() && !$detect->isTablet())
14 
15if ($detect->isMobile() && !$detect->isTablet())
16 
17// Alternative to $detect->isAndroidOS()
18$detect->is('AndroidOS');
19  
20// Batch usage
21foreach($userAgents as $userAgent){
22  $detect->setUserAgent($userAgent);
23  $isMobile = $detect->isMobile();
24}
25  
26// Version check.
27$detect->version('iPad'); // 4.3 (float)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多