php 函数 ereg_replace() 已弃用 - 如何清除此错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3132844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Function ereg_replace() is deprecated - How to clear this bug?
提问by Pradip
I have written following PHP code:
我编写了以下 PHP 代码:
$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
已弃用:不推荐使用函数 ereg_replace()
How can I resolve this warning.
我该如何解决此警告。
回答by Quentin
Switch to preg_replaceDocsand 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).
切换到preg_replaceDocs并更新表达式以使用 preg 语法 (PCRE) 而不是 ereg 语法 (POSIX) ,其中Docs存在差异(就像它在ereg_replaceDocs手册中所说的那样)。
回答by Krishna Tripathee
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 );
回答by Mark Baker
change the call to ereg_replace to use preg_replaceinstead
呼叫改变ereg_replace到使用的preg_replace代替
回答by Amadan
http://php.net/ereg_replacesays:
Note: As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension.
注意:从 PHP 5.3.0 开始,regex 扩展被弃用,取而代之的是PCRE 扩展。
Thus, preg_replaceis in every way better choice. Note there are some differences in pattern syntax though.
因此,preg_replace在各方面都是更好的选择。请注意,虽然模式语法存在一些差异。
回答by Darko Kenda
回答by Wevah
IIRC they suggest using the preg_functions instead (in this case, preg_replace).
IIRC 他们建议改用这些preg_函数(在本例中为preg_replace)。

