我目前正在研究一些用于检测手机的 PHP 代码,这可能很容易.
I am currently looking at some code for PHP detection of mobiles, which is probably quite easy.
现在我遇到了一个问题 - 我想让在我的 MVC 框架中为平板电脑、手机和网页制作独特的视图文件成为可能.所以我需要将平板电脑与其他移动设备分开.
Now I just have got one problem - I want to make it possible to make unique view-files in my MVC-framework for tablets, mobiles and web pages. So I need to split the tablet from the rest of the mobile devices.
目前这是我正在使用的代码:
Currently this is the code, that I am using:
public function isMobile()
{
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|sagem|sharp|sie-|smartphone|sony|symbian|t-mobile|telus|up.browser|up.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
return true;
else
return false;
}
但这还不够 - 唯一的检查是设备是否是移动设备 - 如果不是,则作为标准告诉框架,我们在计算机上.最后一部分没问题 - 但我想在实际手机中拆分移动设备 - 以及第二组,应该是平板电脑.
But this is not enough - the only check is wheter the device is a mobile device - if not it is as standard telling the framework, that we're on a computer. The last part is ok - but I want to make a split of the mobile devices in actual mobiles - and in a secound group, which should be tablets.
我希望,我已经清楚地表达了我的愿望,我希望您能以一种好的方式提供一些意见来实现这一目标.
I hope, that I have made my wish clear, and I hope, that you have some input in a good way to achieve this.
提前致谢.
这里是一个包含单独检测每个平台的方法的类.
Here is a class with methods for detecting each platform individually.
这篇关于检测移动设备 - 和平板设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!