Johan Ronström
BLOGG
Aug
23

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:

embedcodes.txt
embedcodes.php

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

Ideas - Johan @ 20:53 |

4 kommentarer

  1. Erik Ronström skriver:

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

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

  2. Johan skriver:

    Den matchar YouTubes nya korta adressformat
    http://youtu.be/o6TOdp9cJZk
    plus den gamla vanliga såklart.

  3. Erik Ronström skriver:

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

  4. Johan skriver:

    yees, det ska den ju!

Skriv en kommentar

Alla kommentarer godkänns innan de publiceras.

XHTML: Tillåtna tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>