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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With