Bitte lesen:
Ein persönlicher Aufruf von
Bunnybase-Gründer Kim Il-sung

Videos von youtube & Co einbinden

<?php

  function get_video_from_link( $link ) {
    // mögliche content provider
    $providers = array(
      'youtube.com' => array(
        'name'   => 'youtube.com',
        'regexp' => '/[^09,^az]v=([^&]*)/i',
        'match'  => 1,
        'embed'  => ''.
          '<object width="425" height="355">'.
            '<param name="movie" value="http://www.youtube.com/v/%%ID%%&rel=1">'.
            '</param>'.
            '<param name="wmode" value="transparent">'.
            '</param>'.
            '<embed '.
              'src="http://www.youtube.com/v/%%ID%%&rel=1" '.
              'type="application/x-shockwave-flash" '.
              'wmode="transparent" '.
              'width="425" '.
              'height="355"'.
            '></embed>'.
          '</object>',
      ),
    );

    // feststellen des anbieters
    preg_match( '/http:\/\/(www\.)?([^\/]*)/i', $link, $matches );
    if( array_key_exists( strtolower( $matches[2] ), $providers ) ) {
      $provider = $providers[strtolower($matches[2])];

    } else {
      return false;
    
    }
    
    // zurueckgeben der video daten zum einbinden in die seite
    preg_match( $provider['regexp'], $link, $matches );
    $video['id']       = $matches[$provider['match']];
    $video['embed']    = str_replace( '%%ID%%', $video['id'], $provider['embed'] );
    $video['provider'] = $provider['name'];
    
    if( $video ) {
      return $video;

    } else {
      return false;

    }

  }

  $links = array(
    'http://youtube.com/watch?v=SKwp8T8zTPI',
    'http://youtube.com/watch?v=8sS91v0rvRE&feature=related',
    'http://www.youtube.com/watch?v=8sS91v0rvRE&feature=related'
  );

  foreach( $links as $link ) {
    echo $link .' => '. print_r( get_video_from_link( $link ) ) . '<br />';

  }

?>