【问题标题】:Regex Iframe tags正则表达式 iframe 标签
【发布时间】:2016-10-10 13:04:01
【问题描述】:

如何使用正则表达式“剪切”字符串中的 iframe 标记,以便将它们放置在页面上的其他位置。

我的页面在文章顶部显示了一张图片,但是当我使用我的 cms 添加视频时,我希望将嵌入的视频放置在该图片的位置上。

如何在字符串中查找这些标签并将它们变成数组的一部分?

例如:

字符串:

This is the article title
<iframe width="853" height="480" src="https://www.youtube.com/embed/23r23ffwe" frameborder="0" allowfullscreen></iframe>
This is the article text

应该可以像这样使用:

$array[0] (title)
$array[1] (iframe)
$array[2] (text)

如何选择这些标签?我在stackoverflow上找不到明确的答案。

【问题讨论】:

标签: php regex iframe


【解决方案1】:
preg_match_all('@(.*)(<iframe(?:.*?)</iframe>)(.*)@gs', $html, $matches, PREG_SET_ORDER);

然后查看$matches 数组。或View regex in online debugger

【讨论】:

  • 谢谢!我需要什么
猜你喜欢
  • 2015-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-23
相关资源
最近更新 更多