Get Youtube ID from URL using PHP

Jul 6, 2015 07:15 · 31 words · 1 minute read 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');