Video embed codes

By | August 23, 2010
Share

I’m building a site where users can embed video into their profiles. Letting people use custom HTML is way too risky, so I’ve made a script that detects the video service and builds the embed code from the video URL.

I have added the video sites most popular here right now, I’m probably going to add more on request. I’ve minimized the embed codes as much as I can, removed all unnecessary (for me) parameters.

The video sites as of now are:
YouTube
MySpace
Google
Vimeo
Yahoo
Flickr

And audio:
Soundcloud

(separating audio and video might not be necessary for other sites)
Here are the PHP functions, getVideoEmbedHtml() and getAudioEmbedHtml() with some testdata at the top:

embedcodes.txt
embedcodes.php

if you run the PHP script you can see the outputted embed codes in the source.

4 thoughts on “Video embed codes

  1. Erik Ronström

    Grymt! Men är det inte en punkt för mycket i “youtu.be”?

    preg_match(‘/^http\:\/\/youtu.be\//’, $videourl)

  2. Erik Ronström

    Men då borde väl punkten vara escapad? (\.) Annars matchar den ju vilket tecken som helst!

Leave a Reply

Your email address will not be published.