fork download
  1. <?php
  2.  
  3. $test = <<<TEST
  4. http://w...content-available-to-author-only...e.com/attribution_link?a=_NDwn20sMog&u=/watch?v=zl-GC1
  5. 6vBm4&feature=share
  6. TEST;
  7.  
  8. $test = preg_replace('/\s/', '', $test); // NOTE: Scrub potential whitespace.
  9. // NOTE: (&.*)* added to the end of the original pattern to match the
  10. // rest of the query string if any.
  11. preg_match('/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|attribution_link\?a=.+?watch.+?v(?:%|=)|watch\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})(&.*)*/', $test, $matches);
  12.  
  13. var_dump($matches);
  14.  
  15. ?>
Success #stdin #stdout 0.02s 24144KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  string(90) "http://w...content-available-to-author-only...e.com/attribution_link?a=_NDwn20sMog&u=/watch?v=zl-GC16vBm4&feature=share"
  [1]=>
  string(11) "zl-GC16vBm4"
  [2]=>
  string(14) "&feature=share"
}