Home > Article > Backend Development > php5.3 prompts Function ereg() is deprecated Error problem solution, eregdeprecated_PHP tutorial
The example in this article describes how to solve the problem of Function ereg() is deprecated Error in php5.3. Share it with everyone for your reference. The specific implementation method is as follows:
1. Question:
PHP 5.3 ereg() cannot be used normally. The prompt "Function ereg() is deprecated Error" is because it is longer than ereg. The function has been upgraded and needs to be preg_matched using // to rule. Of course, php5.3 also uses ereg The rhythm is abandoned.
PHP 5.3 ereg() cannot be used normally, prompting "Function ereg() is deprecated Error".
The root of the problem is that there are two regular expression methods in PHP, one is posix and the other is perl. PHP6 intends to abolish the posix regular expression method, so a preg_match was added later. The solution to this problem is very simple, just add a filter prompt information symbol before ereg: change ereg() into @ereg(). This blocks the prompt information, but the fundamental problem is still not solved. Before PHP version 5.2, ereg was used normally. After PHP 5.3, preg_match must be used instead of ereg. So it needs to be like this.
Original: ereg("^[0-9]*$",$page) becomes: preg_match("/^[0-9]*$/",$page)
Special reminder: The obvious expression difference between posix and perl is whether to add slashes, so compared with ereg, the latter adds two "/" symbols before and after the regular expression, which is indispensable.
For example:
Before changed:
Supplement: This problem will not occur in versions before php5.2.
I hope this article will be helpful to everyone’s PHP programming design.