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```. You don't need to escape code in backticks, Markdown does that for you.

Sadly, it's kind of broken. WordPress only accepts a subset of HTML in comments, which makes sense, because certainly some HTML can't be allowed, like <script> tags. But this stripping happens before the comment is processed by Markdown (via Jetpack). It seems to me that would be reversed, because after Markdown processes code in backticks, it's escaped, thus safe. If you think you can fix this issue, get in touch!

If you need to make sure the code (typically HTML) you post absolutely posts correctly, escape it and put it within <pre><code> tags.

Current ye@r *

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