Function ereg_replace() is deprecated - How to cle

2019-01-03 18:14发布

I have written following PHP code:

$input="menu=1&type=0&";

print $input."<hr>".ereg_replace('/&/', ':::', $input);

After running above code, it gives following warning,

Deprecated: Function ereg_replace() is deprecated

How can I resolve this warning.

6条回答
Explosion°爆炸
2楼-- · 2019-01-03 18:36

change the call to ereg_replace to use preg_replace instead

查看更多
来,给爷笑一个
3楼-- · 2019-01-03 18:38

Switch to preg_replaceDocs and update the expression to use preg syntax (PCRE) instead of ereg syntax (POSIX) where there are differencesDocs (just as it says to do in the manual for ereg_replaceDocs).

查看更多
霸刀☆藐视天下
4楼-- · 2019-01-03 18:38

Here is more information regarding replacing ereg_replace with preg_replace

查看更多
家丑人穷心不美
5楼-- · 2019-01-03 18:39

IIRC they suggest using the preg_ functions instead (in this case, preg_replace).

查看更多
仙女界的扛把子
6楼-- · 2019-01-03 18:40

http://php.net/ereg_replace says:

Note: As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension.

Thus, preg_replace is in every way better choice. Note there are some differences in pattern syntax though.

查看更多
Juvenile、少年°
7楼-- · 2019-01-03 18:43
print $input."<hr>".ereg_replace('/&/', ':::', $input);

becomes

print $input."<hr>".preg_replace('/&/', ':::', $input);

More example :

$mytext = ereg_replace('[^A-Za-z0-9_]', '', $mytext );

is changed to

$mytext = preg_replace('/[^A-Za-z0-9_]/', '', $mytext );
查看更多
登录 后发表回答