gpt4 book ai didi

php - php中检测ie10、
转载 作者:太空狗 更新时间:2023-10-29 16:52:41 25 4
gpt4 key购买 nike

我有这段代码来检测用户是否使用 IE 浏览器,但是我想检测它是 ie 10 还是低于 ie 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
}
?>

Demo Here>>

编辑:分成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

}
?>

Demo Here>>

关于php - php中检测ie10、<ie10等浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16474948/

25 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com