問題描述
我目前正在研究一些用于檢測手機的 PHP 代碼,這可能很容易.
I am currently looking at some code for PHP detection of mobiles, which is probably quite easy.
現(xiàn)在我遇到了一個問題 - 我想讓在我的 MVC 框架中為平板電腦、手機和網(wǎng)頁制作獨特的視圖文件成為可能.所以我需要將平板電腦與其他移動設(shè)備分開.
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;
}
但這還不夠 - 唯一的檢查是設(shè)備是否是移動設(shè)備 - 如果不是,則作為標(biāo)準(zhǔn)告訴框架,我們在計算機上.最后一部分沒問題 - 但我想在實際手機中拆分移動設(shè)備 - 以及第二組,應(yīng)該是平板電腦.
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.
我希望,我已經(jīng)清楚地表達(dá)了我的愿望,我希望您能以一種好的方式提供一些意見來實現(xiàn)這一目標(biāo).
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.
- https://github.com/serbanghita/mobile-detect
這篇關(guān)于檢測移動設(shè)備 - 和平板設(shè)備的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!