Posted By

jhonqwerty on 10/14/10


Tagged

regex function YouTube


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

bobbym245
vehler


Youtube ID extractor


 / Published in: PHP
 

Youtube ID simple extractor

  1. <?php
  2. function youtubeid($url) {
  3. if (preg_match('%youtube\\.com/(.+)%', $url, $match)) {
  4. $match = $match[1];
  5. $replace = array("watch?v=", "v/", "vi/");
  6. $match = str_replace($replace, "", $match);
  7. }
  8. return $match;
  9. }
  10.  
  11. //Usage
  12. $video_id = youtubeid("http://www.youtube.com/watch?v=Fv2aS8YtpmU");
  13.  
  14. echo $video_id;
  15.  
  16. ?>

Report this snippet  

You need to login to post a comment.