PHP is a simple method for judging mobile phone devices. php is used to determine mobile phones.
This example describes how PHP can easily identify mobile devices. We will share this with you for your reference. The details are as follows:
Nowadays, mobile internet is becoming more and more popular, and many websites are browsing on mobile phones. To better display webpages on mobile phones, we have chosen to use CSS media queries to create responsive templates, however, this also has drawbacks. For example, some websites have CMS-type structures, and too much content needs to be displayed. the CSS media query design response style only hides but loads the content, to make the mobile phone end display content more quickly, we can use this PHP to determine the phone device code. This code can be used to conveniently display or not display custom content.
This is the PHP function code used to determine the mobile phone device. It is copied to the PHP function library and called:
<? Phpfunction is_mobile () {$ user_agent = $ _ SERVER ['HTTP _ USER_AGENT ']; $ mobile_browser = Array ("mqqbrowser", // mobile QQ Browser "opera mobi ", // cell phone opera "juc", "iuc", // uc Browser "fennec", "ios", "applewebKit/420", "applewebkit/525 ", "applewebkit/532", "ipad", "iphone", "ipaq", "ipod", "iemobile", "windows ce ", // windows phone "240 × 320", "480 × 640", "acer", "android", "anywhereyougo.com", "asus", "audio", "B Lackberry "," 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"); $ is_mobile = false; foreach ($ mobile_browser as $ device) {if (stristr ($ user_agent, $ device) {$ is_mobile = true; break ;}} return $ is_mobile ;}?> // This is the call code. You can add the if statement: <? Php if (is_mobile ():?> // Set the content of the mobile phone <? Php endif;?>