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

时间:2012-07-11 07:06:39

标签: php

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

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

工作正常但我收到错误已弃用:函数ereg_replace()。 我想问一下在php中使用弃用函数是否有任何副作用?如果有其他替代品。我试过preg但它也没用。在此先感谢:)

1 个答案:

答案 0 :(得分:2)

使用已弃用的函数是不好的做法,你可以使用它们,但是没有建议,因为它们不再受支持,可能不会出现在更高版本的php中。

你应该使用preg_replace而不是你的功能(我认为你已经尝试过,但查看文档,也许你做错了)

编辑在评论中回答问题:

您的替换将如下所示:

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

请注意,模式以正斜杠/.*\.(.*)$/

开头和结尾