已弃用的 PHP 函数的替代方法:eregi_replace

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

Alternative for deprecated PHP function: eregi_replace

phpfunctiondeprecated

提问by Juri

Do anyone know a good alternative for the deprecated eregi_replace function?

有谁知道已弃用的 eregi_replace 函数的一个很好的替代方案?

I need it for this sniplet:

这个片段我需要它:

$pattern = "([a-z0-9][_a-z0-9.-]+@([0-9a-z][_0-9a-z-]+\.)+[a-z]{2,6})";
$replace = "<a href=\"mailto:\1\">\1</a>";
$text = eregi_replace($pattern, $replace, $text);

Thanks!

谢谢!

回答by Guillaume Flandre

preg_replace

preg_replace

http://php.net/manual/fr/function.preg-replace.php

http://php.net/manual/fr/function.preg-replace.php

$pattern = "/([a-z0-9][_a-z0-9.-]+@([0-9a-z][_0-9a-z-]+\.)+[a-z]{2,6})/i";
$replace = "<a href=\"mailto:\1\">\1</a>";
$text = preg_replace($pattern, $replace, $text);

回答by leepowers