Home >Backend Development >PHP Tutorial >PHP 5.3 ereg() error problem solving_PHP tutorial

PHP 5.3 ereg() error problem solving_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:33:11895browse

In the php5.3 environment, error messages such as Deprecated: Function ereg() is deprecated in... and Deprecated: Function ereg_replace() is deprecated in... sometimes appear.

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, it turns out:

if (!ereg("^[0-9]+$",$id))

changed to:

if (!preg_match("/^[0-9]+$/",$id))

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.

Tips: This problem will not occur in versions before php5.2.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752537.htmlTechArticleIn the php5.3 environment, sometimes Deprecated: Function ereg() is deprecated in... and Deprecated: Function ereg_replace() is deprecated in... These types of error messages. PHP 5.3 ere...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn