Embed youtube videos, the easy way!

I just found a neat piece of code I want to share.

If you want to let your client embed youtube videos and don’t want to make it to complicated for them make them a Backend textfield where they past the Video URL.

With this call $video = json_decode(file_get_contents(sprintf(‘http://www.youtube.com/oembed?url=%s&format=json’, urlencode($url)))), you get an object congaing most info you will need about the Video.

$video->html gives you the embed code, $video->title, you guessed it,  the title.


Leave a comment