Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is `ereg` deprecated in PHP?

Tags:

php

posix-ere

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?

like image 723
Starx Avatar asked May 14 '26 16:05

Starx


1 Answers

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().

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.

like image 68
abelito Avatar answered May 16 '26 06:05

abelito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!