Web Analytics Made Easy -
StatCounter ereg to preg_match code - CodingForum

Announcement

Collapse
No announcement yet.

ereg to preg_match code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ereg to preg_match code

    I' m trying to fix PHP Deprecated problem..

    Old code:

    PHP Code:
    if (ereg(".gif$"$file)) { 
    I changed code as given below, is it correct? else please suggest me corrections.

    New Code:

    PHP Code:
    if (preg_match("/.gif$/"$file)) { 

  • #2
    . is a special character in regular expressions.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

    Comment


    • #3
      Like in your previous thread, the regular expression is entirely unnecessary, because PHP has a built-in function to get the extension:
      PHP Code:
      if (pathinfo($filePATHINFO_EXTENSION) == 'gif'
      So rather than blindly converting all ereg_* calls into preg_* calls, you should use your brain and your Google-fu to solve each underlying problem. That's what programming is all about.

      Comment


      • #4
        Originally posted by Jacques1 View Post
        Like in your previous thread, the regular expression is entirely unnecessary, because PHP has a built-in function to get the extension:
        PHP Code:
        if (pathinfo($filePATHINFO_EXTENSION) == 'gif'
        So rather than blindly converting all ereg_* calls into preg_* calls, you should use your brain and your Google-fu to solve each underlying problem. That's what programming is all about.
        I understood. I also did several searches on Google to get an idea but didn't see better solution. I will explore more in next time. thank you

        Comment

        Working...
        X