0

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

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.