tags:

views:

203

answers:

3

Why is ereg deprecated in PHP?

I had a lot of functions which used this, now they always give warning.

What is the alternative of this too?

+3  A: 

http://pl.php.net/manual/en/function.ereg.php

Note: As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED notice. See the list of differences for help on converting to PCRE.

hsz
+2  A: 

It says why on the documentation page:

Note: As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED notice. See the list of differences for help on converting to PCRE.

Dean Harding
+1  A: 

Ereg is deprecated because it was replaced by the the PCRE extension. The reason(s) it was replaced and deprecated is answered in the below link, but to save you some time here is the copy and pasted answer:

Note: preg_match(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg().

http://stackoverflow.com/questions/1361591/php-ereg-vs-preg

One difference between the two is that ereg looks for the longest matching result while preg looks for the first result. Here is the list of differences between the two to help you in determining how best to go about updating your code: http://www.php.net/manual/en/reference.pcre.pattern.posix.php

It should be of note that PHP 6.0 has COMPLETELY removed ereg, so if you are eventually going to be moving your code to a newer server that may use PHP 6.0, the ereg function will no longer be available.

abelito