You are here

function asset_youtube_extract_id in Asset 5

Same name and namespace in other branches
  1. 6 asset_youtube/asset_youtube.module \asset_youtube_extract_id()
1 call to asset_youtube_extract_id()
asset_youtube_asset_type in asset_youtube/asset_youtube.module

File

asset_youtube/asset_youtube.module, line 3

Code

function asset_youtube_extract_id($text) {
  $matches = array();

  // first try to match the embed tag
  preg_match('/param[^>]*value=\\"http:\\/\\/www.youtube.com\\/v\\/([^\\"]*)\\"/', $text, $matches);

  // then the URL
  if (!isset($matches[1])) {

    // http://youtube.com/watch?v=9193duFdUec
    preg_match('/http:\\/\\/www.youtube.com\\/watch\\?v=(.*)^\\"/', $text, $matches);
  }
  return isset($matches[1]) ? $matches[1] : false;
}