dqmq0654 2016-10-10 13:04
浏览 384
已采纳

正则表达式iframe标签

How can I "cut out" iframe tags in a string using regex so I can place them somewhere else on my page.

I got a page which shows an image at the top of an article, but when I add a video using my cms, I want that embedded video to be placed on the position of that image instead.

How can I look for those tags in a string and make them part of an array?

For example:

String:

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

Should be usuable like:

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

How can I select these tags? I can't find a clear answer on stackoverflow.

  • 写回答

1条回答 默认 最新

  • duanchun6148 2016-10-10 13:11
    关注
    preg_match_all('@(.*)(<iframe(?:.*?)</iframe>)(.*)@gs', $html, $matches, PREG_SET_ORDER);
    

    Then see $matches array. Or View regex in online debugger

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题