- preg_match: documentation ( source)
<?php
$youtube = "https://www.youtube.com/watch?v=9g30pPikveg&feature=youtu.be";
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $youtube, $matches);
echo $matches[1];