致命错误:未捕获错误:调用未定义的函数 ereg_replace() PHP 7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39469264/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:55:10  来源:igfitidea点击:

Fatal error: Uncaught Error: Call to undefined function ereg_replace() PHP 7

phpphp-7ereg-replace

提问by Hyder B.

below code is giving me the fatal error in php 7

下面的代码给了我 php 7 中的致命错误

    $jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));

is there any way to make it compatible with php 7?

有没有办法让它与php 7兼容?

回答by Hyder B.

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手册中所说的那样)。

Your above code should be this way:

你上面的代码应该是这样的:

$jquery_click_hook = preg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));

回答by KinjalMistry

ereg_replace function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0. So you must have to use preg_replace()function instead of ereg_replace()

ereg_replace 函数在 PHP 5.3.0 中被弃用,在 PHP 7.0.0 中被移除。所以你必须使用preg_replace()函数而不是 ereg_replace()