1

When I write this code :

$pat='^[A-Za-z][a-zA-Z0-9_\-\.]*@[a-zA-z0-9\-]+\.[a-zA-Z0-9\-\.]+$';
$mail='javad.y1';
ereg($pat,$mail);

I'm getting this error :

Deprecated: Function ereg() is deprecated in C:\wamp\www\Test\test.php on line 10

Javad Yousefi
  • 2,250
  • 4
  • 35
  • 52
  • 1
    Because `ereg` is **deprecated**. See [deprecated errors while setting up Built2Go Car Dealer on xampp](http://stackoverflow.com/questions/5227657/deprecated-errors-while-setting-up-built2go-car-dealer-on-xampp), then [http://php.net/ereg](http://php.net/ereg). – deceze Mar 25 '11 at 23:38

3 Answers3

6

The statement "Error : Deprecated: Function ereg() is deprecated" pretty much answers the question for you.

In terms of using the more modern equivalent, see the Differences from POSIX regex page in the PHP manual and the preg_match function you'll need to use going forward.

Alternatively, for some exciting further reading why not check out: http://en.wikipedia.org/wiki/Deprecated

UPDATED WITH SAMPLE CODE

If you're attempting to validate an email, then you could use:

if(preg_match("/^[A-Za-z][a-zA-Z0-9_\-\.]*@[a-zA-z0-9\-]+\.[a-zA-Z0-9\-\.]+/", $email)) {
    // The email is valid. Yay for stuff! And things!
}

That said, I wouldn't say this is necessarily the best approach.

John Parker
  • 54,048
  • 11
  • 129
  • 129
2

Because ereg() is deprecated. You should use preg_match() instead.

CanSpice
  • 34,814
  • 10
  • 72
  • 86
0

You now youe Perl-compatible RegEx instead.

POSIX RegEx:

As of PHP 5.3.0 this extension is deprecated,  calling any function

provided by this extension will issue an E_DEPRECATED notice.

Raffael
  • 19,547
  • 15
  • 82
  • 160