youtube url video id


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

Returns the video id for any type of youtube url that holds one.


Copy this code and paste it in your HTML
  1. /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  2.  
  3. Returns the video id for any type of youtube url that holds one, like the links bellow.
  4.  
  5. http://www.youtube.com/watch?v=pkPgYbdQ1kQ&feature=feedu
  6. www.youtube.com/watch?v=pkPgYbdQ1kQ&feature=feedu
  7. youtube.com/watch?v=pkPgYbdQ1kQ&feature=feedu
  8. http://www.youtube.com/v/pkPgYbdQ1kQ&feature=feedu
  9. www.youtube.com/v/pkPgYbdQ1kQ&feature=feedu
  10. http://youtu.be/pkPgYbdQ1kQ
  11. youtu.be/pkPgYbdQ1kQ
  12.  
  13. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
  14.  
  15. function uTubeId($url){
  16. $url = preg_replace('((http://)?(www.)?(youtube.com|youtu.be)(/v/|/watch\?v=|/)([a-zA-Z0-9_-]*)(.*))',"$5",$url);
  17. return (preg_match('(([a-zA-Z0-9_-]*){11,18})',$url) ? $url : '');
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.