- var_dump: documentation ( source)
- preg_match: documentation ( source)
<?php
function parse_yturl($url)
{
$pattern = '#^(?:https?://)?(?:www|m\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v=|/watch\?.+&v=))([\w-]{11})(?:.+)?$#x';
preg_match($pattern, $url, $matches);
return isset($matches[1]) ? $matches[1] : false;
}
var_dump(parse_yturl("http://www.youtube.com/?feature=player_embedded&v=dQw4w9WgXcQ"));