从嵌入的iframe代码中获取YouTube视频ID

zac*_*ack 3 php regex youtube iframe

我想使用preg_match或regex从YouTube嵌入代码中获取YouTube视频ID.举个例子

<iframe width="560" height="315" src="//www.youtube.com/embed/0gugBiEkLwU?rel=0" frameborder="0" allowfullscreen></iframe> 
Run Code Online (Sandbox Code Playgroud)

我想拿这个ID 0gugBiEkLwU

任何人都可以告诉我如何做到这一点.真的很合适你的帮助.

l'L*_*L'l 6

将此模式与捕获组一起使用应该为您提供所需的字符串:

d\/(\w+)\?rel=\d+"
Run Code Online (Sandbox Code Playgroud)

例如:https://regex101.com/r/kH5kA7/1