SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot cwebmedia's Avatar
    Join Date
    Nov 2002
    Location
    Calgary, Alberta, Canada
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular Expression to Grab Browser Version?

    Hello. I'm looking to create a regular expression to pull the version number(s) out of an HTTP_USER_AGENT string. What I want to be able to do pull the version out, assign it to a variable, then compare it to see if its less than (or greater that) and certain number.

    What I've been doing is:

    PHP Code:
    // determine browser version
    if ($browser_array['browser'] == 'Internet Explorer') {
         
    ereg ('(MSIE)[ \/]([0-9\.]+)'$browser_string$version);
    } elseif (
    $browser_array['browser'] == 'Netscape') {
         
    ereg ('???'$browser_string$version);

    I've got my style sheet imported into the page hence if the user has an older browser the style is not displayed. What I want to do is, when that has been determined, I want PHP to remove a flash animation that is going to be in the page and replace it with a blurb about standards then a link to WaSP.

    My main problem here is that I'm very new to regular expressions and not able to make advanced match strings at all. The one above in the example was taken from a free browser detection script that I found hence I'm not even 100% certain on what it is doing.

    Does that make sense?

    ... I hope that makes sense ...
    Last edited by cwebmedia; Dec 26, 2002 at 17:36.

    Keep smiling ...
    It makes people wonder what you're up to ...

  2. #2
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're worried about standards you may want to remember that there are other browsers than Netscape and IE, not to mention wireless devices etc. That is the whole point of following standards, right?

    As far as your question, I think the percentage using MSIE below 5.0 is statistically insignificant. I would ditch the regexp idea, sniff for netscape and see if "4." appears in the string.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •