php - 移动和桌面探测器
问题描述
我有一个滑块,每个滑块中都有一个视频,是否可以从移动设备进入时显示图片,如果使用桌面输入显示视频?
解决方案
您可以使用此功能来检测设备
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);
}
推荐阅读
- project-reactor - 使用 Mono.fromCallable 时获取 Mono 上下文
- javascript - Jest 中的嵌套模拟函数
- c# - 如何返回tableA的所有列和连接表的一列
- python - 从 Python 运行 psql 命令以从 PostgreSQL 转储文件中恢复
- python - 芹菜任务有没有办法确定工人是否正在等待它完成以便它可以关闭?
- bash - 检查文件是否存在于路径中的任何目录中,或者当前目录是否在 git 项目中
- sql - SQL 客户端 CPU 利用率
- php - PHP 脚本停止在共享主机上运行
- css - 如何在 Div 上方溢出文本 - 即使父 Div 为 0% 宽度
- ios - switch 语句返回类实例