Forum Moderators: coopster

Message Too Old, No Replies

ereg() is now preg match ?

depricated versions

         

Matthew1980

8:57 pm on Mar 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people of the forum,

I have just been 'tidying' up some old code, and found that ereg() is now depricated, at least that what php.net has confirmed, my problem is this (intentionally no semi-colon):-

!preg_match("^([a-z]|[0-9]|\.|-|_)+@([a-z]|[0-9]|\.|-|_)+\.([a-z]|[0-9]){2,4}$", $admin_email)


This generates a warning saying:-

No ending delimiter '^' found


Could someone point out where this should be as this isn't my strong suite..

Cheers,
Mrb

g1smd

8:59 pm on Mar 1, 2010 (gmt 0)

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



I have been eyeing this with alarm for some while, as I have some scripts from years ago that are still packed full of ereg directives.

Matthew1980

9:05 pm on Mar 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there g1smd,

Well it was a suprise to me too, I just need to know what's wrong with the pattern in there now, as this worked fine in ereg() & eregi(), but now it generates a warning that wasn't there yesterday! It must have been though, I haven't upgraded to the latest php release, I'm still on 5.3.0, until I need a reinstall ;-p

Cheers,

MRb

eelixduppy

9:32 pm on Mar 1, 2010 (gmt 0)



The pattern needs to be surrounded by a start and end deliminator to separate the pattern from the pattern modifiers.

Try the following:

!preg_match("/^([a-z]|[0-9]|\.|-|_)+@([a-z]|[0-9]|\.|-|_)+\.([a-z]|[0-9]){2,4}$/", $admin_email)

Matthew1980

9:39 pm on Mar 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Eelixduppy,

Great, that's better no errors/warnings. I understand from that, if I was to place an 'i' after the last slash, it would make it case insensitive then? That's the gist I get from the php manual anyway...

Cheers,

MRb

eelixduppy

9:45 pm on Mar 1, 2010 (gmt 0)



Yes, that is correct. There are other modifiers too that allow you to do various things. here's the list if you haven't already found it: [php.net...]

dreamcatcher

7:35 am on Mar 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The deprecated warnings for PHP6 were added in PHP5.3 to let developers know what changes are coming in PHP6.

dc

coopster

1:44 pm on Mar 3, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Earlier notice and discussion (for reference):
No more ereg regular expressions! [webmasterworld.com]