Home >Backend Development >PHP Tutorial >PHP class library for detecting mobile devices (cell phones)

PHP class library for detecting mobile devices (cell phones)

WBOY
WBOYOriginal
2016-08-08 09:24:431056browse

Mobile_Detect is a lightweight open source mobile device (mobile phone) detection PHP Class, which uses the string in User-Agent combined with HTTP Header to detect the mobile device environment. The most powerful thing about this device detection PHP class library is that it has a very complete library that can detect the device type used (including operation type, mobile phone brand, etc.) and browser details.

http://mobiledetect.net/

//使用实例
 
include 'Mobile_Detect.php';
$detect = new Mobile_Detect();
 
// Check for any mobile device.
if ($detect->isMobile())
 
// Check for any tablet.
if($detect->isTablet())
 
// Check for any mobile device, excluding tablets.
if ($detect->isMobile() && !$detect->isTablet())
 
if ($detect->isMobile() && !$detect->isTablet())
 
// Alternative to $detect->isAndroidOS()
$detect->is('AndroidOS');
  
// Batch usage
foreach($userAgents as $userAgent){
  $detect->setUserAgent($userAgent);
  $isMobile = $detect->isMobile();
}
  
// Version check.
$detect->version('iPad'); // 4.3 (float)

Source: http://www.oschina.net/code/snippet_118180_16788

The above introduces the PHP class library for detecting mobile devices (mobile phones), including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn