ereg conversion to preg_match help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wizardry
    New Member
    • Jan 2009
    • 201

    ereg conversion to preg_match help

    hello -

    i need to convert this string to preg_match to support current version of php. i have googled and found some info but still get an error where it doesnt like my search string.

    Code:
    if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $call_function))
    thanks in advance for your help,

    theo werntz ii
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Your use of the $HTTP_USER_AGEN T is most likely not going to work on 5.3 (or any version after 4.2). You should be using $_SERVER['HTTP_USER_AGEN T'] instead.
    This is because of the register_global s directive, which was used in the past to extract all $_REQUEST, $_COOKIE and $_SERVER variables into the global scope. This has been deprecated since 4.2, and will be removed in 6.0, so it is best to not rely on it.

    As to your regexp, these two if blocks produce the same results in 5.3: (Tested them in Opera 10.10... which oddly enough identifies itself as Opera 9.80...)
    [code=php]if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGEN T'], $matches)) {
    var_dump($match es);
    }

    if (preg_match('#O pera(/| )([0-9]\.[0-9]{1,2})#i', $_SERVER['HTTP_USER_AGEN T'], $matches)) {
    var_dump($match es);
    }[/code]
    The PCRE (preg) pattern is a little different, but not so much that it should be hard to convert old POSIX (ereg) expressions. Just takes a bit of Googling :)

    Comment

    • wizardry
      New Member
      • Jan 2009
      • 201

      #3
      thanks alti will try and repost latter my results!

      Comment

      • wizardry
        New Member
        • Jan 2009
        • 201

        #4
        Thanks alti -

        this has been completed for some time now.

        Comment

        Working...