使用str_replace()

时间:2012-09-06 16:17:02

标签: php

如何删除 onmousedown="return curwt(this, 'http://www.example.com/2009/07/content.html')"使用str_replace( ),我知道如何使用此字符串但无法理解以这种方式配置此字符串以删除onmousedown="all content"的方法。
我试过这种方式:$result = str_replace("onmousedown''", " ", $result);
但它不起作用......任何想法?

2 个答案:

答案 0 :(得分:4)

我认为你想要使用正则表达式

$result = preg_replace('/onmousedown=".*?"/', '', $result);

或者它是否可以是撇号和引号:

$result = preg_replace('/onmousedown=("|\').*?\1/', '', $result);

答案 1 :(得分:0)

你不能使用str_replace,因为它只能替换预定义的字符串,不能使用通配符。

您可以使用preg_replace