Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get YouTube video id from embed iframe code

I want to get the YouTube video ID from YouTube embed code using preg_match or regex. For a example

<iframe width="560" height="315" src="//www.youtube.com/embed/0gugBiEkLwU?rel=0" frameborder="0" allowfullscreen></iframe> 

I want to take the ID 0gugBiEkLwU

Can anyone tell me how to do this. Really appropriate your help.

like image 292
zack Avatar asked Feb 18 '14 05:02

zack


People also ask

How do I find the embedded video ID on YouTube?

How to get a YouTube video ID from a youtube.com page URL. You may be watching the video or just happened to visit a link to a video. The video ID will be located in the URL of the video page, right after the v= URL parameter.

How do I find the embedded ID?

View and Copy unique Embed IDIn Control, navigate to your Events tab. Locate your Web Event to embed. Click the Actions Button, then [Details]. Locate the Embed ID, and copy it as seen within the details page.

How do I get an iframe video?

To embed a video in an HTML page, use the <iframe> element. The source attribute included the video URL. For the dimensions of the video player, set the width and height of the video appropriately. The Video URL is the video embed link.


1 Answers

Using this pattern with a capturing group should give you the string you want:

d\/(\w+)\?rel=\d+"

example: https://regex101.com/r/kH5kA7/1

like image 142
l'L'l Avatar answered Oct 04 '22 17:10

l'L'l