geoffs3310
geoffs3310

Reputation: 13998

php to find youtube embed code

I am writing a script that takes the url of a video on youtube and from that will get the video embed code for that video. I am using

file_get_contents();

to get the page. Once I've got the contents of the page does anyone know how I can extract the embed code?

Thanks

Geoff

Upvotes: 0

Views: 1069

Answers (3)

Eric Redon
Eric Redon

Reputation: 1762

Since YouTube provides an oEmbed service, which offers what you are looking for, I would strongly recommend that you use it instead of attempting manual parsing of the page.

The API to their oEmbed service is explained in this YouTube API Blog Post

Upvotes: 2

geoffs3310
geoffs3310

Reputation: 13998

Don't think i can get the embed code just by getting the file contents because its added into the page dynamically if you click the embed code button. Have to figure out the API

Upvotes: 0

usoban
usoban

Reputation: 5478

Using regular expressions via preg_match, you'll just have to write the right pattern.

Or, if that suits you, you can even use gdata api for youtube or Zend Gdata. Depends on what you want to do.

Upvotes: 1

Related Questions