PHP:如果 Internet Explorer 6、7、8 或 9

2021-12-25 00:00:00 browser php

我想在 PHP 中为不同版本的 Internet Explorer 执行以下操作:

I want to do a conditional in PHP for the different versions of Internet Explorer along the lines of:

if($browser == ie6){//做这个} elseif($browser == ie7) {//做这个 } elseif...

我已经看到类似代码的许多变体,但正在寻找一些非常简单的代码来执行一些简单的 if 和 else 并执行不同的操作.

I have seen many variations on similar code, but looking for something super simple that is very easy to code to do some simple if and else and do different things.

谢谢

我需要这个来向用户显示一些不同的消息,所以 CSS 条件等不好.

I need this to show some different messages to users so CSS conditionals etc are no good.

推荐答案

这是我最终使用的一个变体,它检查 IE8 及以下:

This is what I ended up using a variation of, which checks for IE8 and below:

if (preg_match('/MSIEs(?P<v>d+)/i', @$_SERVER['HTTP_USER_AGENT'], $B) && $B['v'] <= 8) {
    // Browsers IE 8 and below
} else {
    // All other browsers
}

相关文章