Youtube ID extractor


/ Published in: PHP
Save to your folder(s)

Youtube ID simple extractor


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.