Home >Backend Development >PHP Tutorial >php5.3 prompts Function ereg() is deprecated Error problem solution, eregdeprecated_PHP tutorial

php5.3 prompts Function ereg() is deprecated Error problem solution, eregdeprecated_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:14:08818browse

php5.3 prompts Function ereg() is deprecated Error problem solution, eregdeprecated

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:

Copy code The code is as follows:
function inject_check($sql_str) {
$sql_str = strtolower($sql_str);
return eregi('fopen|post|eval|select|insert|and|or|update|delete|'|/*|*|../|./|union|into|load_file|outfile', $sql_str); / / Filter
}

2. Solution:
Find the file location where the code is located:
Copy code The code is as follows:
function inject_check($sql_str) {
$sql_str = strtolower($sql_str);
return preg_match('/fopen|post|eval|select|insert|and|or|update|delete|'|/*|*|../|./|union|into|load_file|outfile/', $sql_str) ; // Filter
}


Note: Be sure to add '/' at the beginning and end . Reference for this paragraph: http://www.bkjia.com/article/38857.htm

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

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/910600.htmlTechArticlephp5.3 prompt Function ereg() is deprecated Error problem solution, eregdeprecated This article describes the php5.3 prompt with an example Function ereg() is deprecated Error problem solution. Share with everyone...
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