Video embed codes
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:
if you run the PHP script you can see the outputted embed codes in the source.
Ideas - Johan @ 20:53 |


Grymt! Men är det inte en punkt för mycket i “youtu.be”?
preg_match(’/^http\:\/\/youtu.be\//’, $videourl)
Skickat 23/8 -10 @ 23:33Den matchar YouTubes nya korta adressformat
Skickat 24/8 -10 @ 9:51http://youtu.be/o6TOdp9cJZk
plus den gamla vanliga såklart.
Men då borde väl punkten vara escapad? (\.) Annars matchar den ju vilket tecken som helst!
Skickat 19/9 -10 @ 17:40yees, det ska den ju!
Skickat 20/9 -10 @ 18:53