in Web & Tech

Get Youtube ID from URL using PHP

<?php
/*
  Get Youtube ID
  @param $url string
  returns the ID of a Youtube Video URL
*/
function get_youtube_id($url) {
  parse_str( parse_url( $url, PHP_URL_QUERY ), $query_string );
  return($query_string['v']);
}

Usage:

get_youtube_id('https://www.youtube.com/watch?v=zWvvvGprR-o');

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)

  • Related Content by Tag