Php 如何删除文本中的iframe src?

Php 如何删除文本中的iframe src?,php,Php,可能重复: 我有一个示例代码: $content = '<p><iframe width="640" scrolling="no" height="150" frameborder="1" marginheight="0" marginwidth="0" src="http://test.html"></iframe></p><p>Hello world</p>'; $text = preg_replace('/<p

可能重复:

我有一个示例代码:

$content = '<p><iframe width="640" scrolling="no" height="150" frameborder="1" marginheight="0" marginwidth="0" src="http://test.html"></iframe></p><p>Hello world</p>';
$text = preg_replace('/<p>\s*(<iframe src="http://test.html" .*>*.<\/iframe>)\s*<\/p>/iU', '', $content);
echo $text;
$content='你好,世界

'; $text=preg_replace('/\s*(*)\s*/iU',''.$content); echo$文本;
如何修复以删除此iframe结果是:
Hello world

$text=preg\u replace('|]*(src=”http://test.html“”[^>]*|',“”,$content);
$text = preg_replace('|<iframe [^>]*(src="http://test.html")[^>]*|', '', $content);

如果不使用正则表达式,则在执行此类任务时应避免使用正则表达式。建议使用DOM函数的遍历前端。以QueryPath为例:
qp($html)->find(“iframe[src=http://test.html]“”->删除()->top()->html()
未关闭
$content
中的
iframe
。如果不是打字错误,我认为正则表达式可能更好…
/\s*

/