我有一个浏览器兼容的Web应用程序,用php和HTML5制作.当客户端从Ipad浏览网站我想要显示不同的横幅时,我有一定的要求.
<?php $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
$android = '1';
}
if(stripos($ua,'iPhone') !== false || stripos($ua,'iPod') !== false || strstr($ua,'iPhone') || strstr($ua,'iPod') ) {
$iPhone = '1';
}
?>
Run Code Online (Sandbox Code Playgroud)
这个条件适用于Android手机和其他设备,但不适用于Ipad.有谁知道如何在PHP中检测Ipad设备.
if (preg_match('/ipad/i', $ua))
{
$platform = 'iPad';
}
Run Code Online (Sandbox Code Playgroud)
这是我用于其余部分的内容:
if (preg_match('/linux/i', $ua))
{
$platform = 'Linux';
}
elseif (preg_match('/ubuntu/i', $ua))
{
$platform = 'Ubuntu';
}
elseif (preg_match('/macintosh|mac os x/i', $ua))
{
$platform = 'Mac';
}
elseif (preg_match('/windows|win32/i', $ua))
{
$platform = 'Windows';
}
if (preg_match('/android/i', $ua))
{
$platform = 'Android';
}
if (preg_match('/palm/i', $ua))
{
$platform = 'Palm';
}
if (preg_match('/iphone/i', $ua))
{
$platform = 'iPhone';
}
if (preg_match('/blackberry/i', $ua))
{
$platform = 'Blackberry';
}
if (preg_match('/ipod/i', $ua))
{
$platform = 'iPod';
}
if (preg_match('/ipad/i', $ua))
{
$platform = 'iPad';
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1280 次 |
| 最近记录: |