将ereg_replace更改为preg_replace

时间:2011-05-04 19:41:00

标签: regex preg-replace ereg-replace

我将如何更改

$output = ereg_replace("<script.*</script>", "", $output);

要预先?

 I tried $output = preg_replace("/<script.*</script>/", "", $output);

由于

编辑:抱歉,搞砸格式化

1 个答案:

答案 0 :(得分:2)

如果您使用/作为分隔符,则必须在模式中每次出现/,或者将其重新定位为分隔符本身,并且将使用以下内容作为分隔符修饰符(可能会失败)。

"/<script.*<\/script>/"

或者您可以轻松完成生活,只需选择不同的分隔符即可。我更喜欢~,因为它很少出现在模式中

"~<script.*</script>~"

更新:请参阅评论说明,此处会发生什么

"~<script.*</script>~siU"
相关问题