PHP preg_match_all多个HTML标记

时间:2016-06-24 10:29:12

标签: php iframe expression preg-match-all

我希望使用单个正则表达式来查找2种多种标记。我在另一个关于此主题的问题中找到了使用|制作(p|h1|table)外观语法的问题,它似乎对我不起作用。

仅用于查找iframe的原始模式

$removeiframe = preg_replace("#<iframe[^>]+>.*?</iframe>#is", "", $descriptiontext);

我尝试使用的模式:

$removeiframe = preg_replace("#<(iframe|img)[^>]+>.*?</(iframe|img)>#is", "", $descriptiontext);

我目前使用最后一种模式得到的回复:

如果文字包含单个iframe,则会返回。

如果文字包含多个iframe,则会返回此

[
    [0] => '<iframe></iframe>'
    [1] => '<img></img><iframe></iframe>'
]

以及我想要的东西

[
    [0] => '<iframe></iframe>',
    [1] => '<img></img>',
    [2] => '<iframe></iframe>',
]

1 个答案:

答案 0 :(得分:0)

你应该使用Ungreedy表达式(添加U标志)