[英]Detect ie10, < ie10 and other browsers in php
我有這個代碼來檢測用戶是否正在使用IE瀏覽器,但是我想檢測它是否是10或者以下版本,即10
<?php
$u_agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/MSIE/i',$u_agent)){
//do something
//HOW TO KNOW IS IE 10
// HOW TO KNOW BROWSER VERSION IS LESS THAN IE 10?
}else{
//hope users would always use other browser than IE
}
?>
這是對的嗎?
<?php
$u_agent = $_SERVER['HTTP_USER_AGENT'];
//IE
if(preg_match('/MSIE/i',$u_agent)){
//IE 10
if(preg_match('/msie 10/i', $_SERVER['HTTP_USER_AGENT'])) {
// DO IE10.
// < IE 10
}else{
// DO < IE10.
}
}else{
//OTHER BROWSERS
//hope users would always use other browser than IE
}
?>
這可能對您有所幫助:
<?php
//echo $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/(?i)msie [10]/',$_SERVER['HTTP_USER_AGENT']))
{
// if IE = 10
echo "version is IE 10"; //rest of your code
}
else
{
// if not 10
echo "version is not 10"; //rest of your code
}
?>
編輯:分為3個案例:
<?php
//echo $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/(?i)msie [1-9]/',$_SERVER['HTTP_USER_AGENT']))
{
// if IE <= 10
echo "version is less than 10"; //rest of your code
} else if(preg_match('/(?i)msie [10]/',$_SERVER['HTTP_USER_AGENT']))
{
// if IE = 10
echo "version is IE 10"; //rest of your code
}
else
{
// if not 10
echo " other browser"; //rest of your code
}
?>
您可以在HTTP_USER_AGENT
服務器變量中輕松檢查IE。
if(preg_match('/msie [2-10]/i', $_SERVER['HTTP_USER_AGENT'])) {
// This user is using IE2 - IE10.
} else {
// Using something else.
}
如果你想專門針對IE10,你可以使用:
if(preg_match('/msie 10/i', $_SERVER['HTTP_USER_AGENT'])) {
// This user is using IE10.
} else {
// Using something else.
}
您還可以查看Trident字符串:
Trident/4* = Internet Explorer 8
Trident/5* = Internet Explorer 9
Trident/6* = Internet Explorer 10
Trident/7* = Internet Explorer 11
Edge/* = Edge
所以對於SVG動畫檢查,我可以這樣做:
$IE = preg_match('/Trident\//i',$_SERVER['HTTP_USER_AGENT']);
您需要的所有參考資料都在這里: -
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.