使用ereg_replace及其替代品的副作用


side effects of using ereg_replace and its replacement

我是php的新手。我有以下代码:

$this->image["format"] = ereg_replace(".*'.(.*)$", "''1", $imgfile);
$this->image["outputformat"] = ereg_replace(".*'.(.*)$", "''1", $save);

它工作正常,但我收到一个错误Deprecated:Function ereg_replace()。我想问一下,在php中使用不推荐使用的函数是否有任何副作用?以及是否有其他替代品。我试过孕,但也不起作用。提前感谢:)

使用不推荐使用的函数是不好的做法,您可以使用它们,但不建议使用,因为它们不再受支持,并且可能不会出现在php的后续版本中。

你应该使用preg_replace来代替你的功能(我认为你已经尝试过了,但请查看文档,也许你做错了什么)

编辑以回答评论中的问题:

你的替代品看起来是这样的:

$this->image["format"] = preg_replace("/.*'.(.*)$/", "''1", $imgfile);
$this->image["outputformat"] = preg_replace("/.*'.(.*)$/", "''1", $save);

请注意,模式以正斜杠/.*'.(.*)$/ 开始和结束