Forum Moderators: coopster

Message Too Old, No Replies

PHP 5.3 ereg, eregi, and ereg replace

         

g1smd

9:29 pm on Jun 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In PHP 5.3 note that
ereg
,
eregi
, and
ereg_replace
are deprecated.

This means that any script using those directives will fail to run at all when the server is upgraded to use PHP 5.3.

I have been putting off upgrading some scripts for many months, but this week they will all be amended.

So far, today, I've tackled a basic CMS and it took only an hour to find and replace all of the affected code and then check the edits very carefully.

The site was updated and back online in less than ten minutes once the decision to make the new scripts live was taken.

The changes are very simple. Change the pattern part of the expression from 'pattern' to '/pattern/' by inserting the slash delimiters as shown.

ereg
becomes
preg_match


ereg_replace
becomes
preg_replace


eregi
becomes
preg_match
but with an extra i added after the final slash in the pattern, like '/pattern/i'.

Here the "pattern" represents any regular expression.

There's nothing difficult or complicated about the changes.

There are literally thousands of sites with more detailed code examples.


In summary, there's no reason to hold off making this update to all of your code. It's a trivial job to fix the lot. However, be warned that you'll also probably be tempted to make other minor changes and fixes at the same time.

Matthew1980

9:42 pm on Jun 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there g1smd,

Yes, I got caught out with this a while back, but in my case I upgraded my wampserver to php5.3.0, and on first run I had error notices on most of my stuff, so I changed (after a bit of research) the patterns, and now all is well.

This is where I first met things like /i as you pointed out in your post, and this prompted me to try and learn some more patterns (as regexp have never been a strong suite of mine) I still don't fully understand it, but usually a google will reveal what I am missing, or a post on here ;)

Cheers,
MRb

rocknbil

12:38 am on Jun 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's really a pain is doing it with someone else's code. You **really** want to fix that too without investing the time to chase their rabbit hole logic. :-(

coopster

5:30 pm on Jun 7, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



split and company are gone too ...
No more ereg regular expressions! [webmasterworld.com]