youtube URL- YouTube,
function getYoutubeVideoId($iframeCode) {
return preg_replace_callback('/<iframe\s+.*?\s+src=(".*?").*?<\/iframe>/', function ($matches) {
$youtubeUrl = $matches[1];
$youtubeUrl = trim($youtubeUrl, '"');
$youtubeUrl = trim($youtubeUrl, "'");
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $youtubeUrl, $videoId);
return $youtubeVideoId = isset($videoId[1]) ? $videoId[1] : "";
}, $iframeCode);
}
$iframeCode = '<iframe width="560" height="315" src="http://www.youtube.com/embed/0gugBiEkLwU?rel=0" frameborder="0" allowfullscreen></iframe>';
echo getYoutubeVideoId($iframeCode);