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
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.
Because ereg()
is deprecated. You should use preg_match()
instead.
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.
精彩评论