Grow your CSS skills. Land your dream job.

Last updated on:

Detect IE5 or IE6

function getMSIE6() {
       $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);
       if (ereg("msie 6", $userAgent) || ereg("msie 5", $userAgent)) {
               return true;
       }
       return false;
}

Comments

  1. Peter Dubrovski
    Permalink to comment#

    Use preg_mach not ereg (depraced in PHP 5.3.0):

    function getMSIE6() {
    $userAgent = strtolower($_SERVER[“HTTP_USER_AGENT”]);
    if (preg_match(“/msie 6/”, $userAgent) || preg_match(“/msie 5/”, $userAgent)) {
    return true;
    }
    return false;
    }

  2. How’s about simply

    function getMSIE56() {
    return preg_match(“/msie [56]{1}/i”, $_SERVER[‘HTTP_USER_AGENT’]);
    }

  3. Permalink to comment#

    Using strpos(“msie 6″, $userAgent) would be even better than eregi and preg_match

  4. @Emmanuel: Using strpos with strict type comparison operator === or !== is the way to go due to strange behavior of it.

  5. Junior
    Permalink to comment#
    function getMSIE6() {
        return (preg_match('msie 6', $_SERVER["HTTP_USER_AGENT"]) || eregi('msie 5', $_SERVER["HTTP_USER_AGENT"]));
    }

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like this:

```
<div>Example code</div>
```

You don't need to escape code in backticks, Markdown does that for you. If anything screws up, contact us and we can fix it up for you.

*May or may not contain any actual "CSS" or "Tricks".