我有一个滑块,每个滑块中都有一个视频,是否可以从移动设备输入时显示图片,以及是否通过台式机输入以显示视频?
答案 0 :(得分:4)
您可以使用此功能来检测设备
public function detectDevice(){
$userAgent = $_SERVER["HTTP_USER_AGENT"];
$devicesTypes = array(
"computer" => array("msie 10", "msie 9", "msie 8", "windows.*firefox", "windows.*chrome", "x11.*chrome", "x11.*firefox", "macintosh.*chrome", "macintosh.*firefox", "opera"),
"tablet" => array("tablet", "android", "ipad", "tablet.*firefox"),
"mobile" => array("mobile ", "android.*mobile", "iphone", "ipod", "opera mobi", "opera mini"),
"bot" => array("googlebot", "mediapartners-google", "adsbot-google", "duckduckbot", "msnbot", "bingbot", "ask", "facebook", "yahoo", "addthis")
);
foreach($devicesTypes as $deviceType => $devices) {
foreach($devices as $device) {
if(preg_match("/" . $device . "/i", $userAgent)) {
$deviceName = $deviceType;
}
}
}
return ucfirst($deviceName);
}