Filter from different Youtube links for the same video using PHP

For different purposes there are a number of Youtube links for the same video. For example: embed, showing related, autoplay etc variations of video links.
Following is a piece of PHP code that helps you filter from different Youtube links for the same video:

<?php

$url = 'youtube.com/watch?v=RVVw1UNfwu8';
$url = 'youtu.be/RVVw1UNfwu8';
$url = 'youtube.com/embed/RVVw1UNfwu8';
$url = 'youtube.com/watch?v=RVVw1UNfwu8&wtv=wtv';
$url = 'https://youtube.com/v/RVVw1UNfwu8';
$url = 'https://youtube.com/vi/RVVw1UNfwu8';
$url = 'youtube.com/?v=RVVw1UNfwu8';
$url = 'youtube.com/?vi=RVVw1UNfwu8';
$url = 'youtube.com/watch?vi=RVVw1UNfwu8';
$url = 'http://youtube.com/v/RVVw1UNfwu8';
$url = 'http://www.youtube.com/v/RVVw1UNfwu8';
$url = 'https://www.youtube.com/v/RVVw1UNfwu8';
$url = 'http://www.youtube.com/watch?dev=inprogress&v=RVVw1UNfwu8&feature=related';
$url = 'https://m.youtube.com/watch?v=RVVw1UNfwu8';

preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
// print_r($matches);

$youtube_link = 'https://www.youtube.com/watch?v='.$matches[1];
echo $youtube_link;
?>

Also following is a PHP function and calls to do the same trick:

	public function youtube_clean_url($x) {
	    preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $x, $matches);
	    return $matches[1];
	}

echo 'https://www.youtube.com/watch?v=' . youtube_clean('https://www.youtube.com/embed/RVVw1UNfwu8') . '<br />';
echo 'https://www.youtube.com/watch?v=' . youtube_clean('youtu.be/RVVw1UNfwu8');