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');

Write a Comment

Comment

  • Related Content by Tag