I am coding a functionality that allows users to enter a Youtube video URL. I would like to extract the video ID from these urls.
Does Youtube API support some kind of function where I pass the link and it gives the video ID in return. Or do I have to parse the string myself?
I am using PHP … I would appreciate any pointers / code samples in this regard.
Thanks
Here is an example function that uses a regular expression to extract the youtube ID from a URL:
It’s an adoption of the answer from a similar question.
It’s not directly the API you’re looking for but probably helpful. Youtube has an oembed service:
Which provides some more meta-information about the URL:
But the ID is not a direct part of the response. However it might contain the information you’re looking for and it might be useful to validate the youtube URL.