public static function get_youtube_id($input)
    {
        // match: <iframe width="560" height="315" src="https://www.youtube.com/embed/dXxEIZTkqMg" ...
        // match: https://www.youtube.com/embed/dXxEIZTkqMg
        if (preg_match('#/embed/([^\?&"]+)#', $input, $matches)) {
            return $matches[1];
        }

        // match: https://www.youtube.com/watch?v=dXxEIZTkqMg&feature=youtu.be
        // match: https://www.youtube.com/watch?vi=dXxEIZTkqMg&feature=youtu.be
        if (preg_match('#vi?=([^&]+)#', $input, $matches)) {
            return $matches[1];
        }

        // match: https://youtu.be/4vXkI1zYyDo
        if (preg_match('#//youtu.be/([^\?&"/]+)#', $input, $matches)) {
            return $matches[1];
        }

        return null;
    }
public static function get_youtube_id($input)
    {
        // match: <iframe width="560" height="315" src="https://www.youtube.com/embed/dXxEIZTkqMg" ...
        // match: https://www.youtube.com/embed/dXxEIZTkqMg
        if (preg_match('#/embed/([^\?&"]+)#', $input, $matches)) {
            return $matches[1];
        }

        // match: https://www.youtube.com/watch?v=dXxEIZTkqMg&feature=youtu.be
        // match: https://www.youtube.com/watch?vi=dXxEIZTkqMg&feature=youtu.be
        if (preg_match('#vi?=([^&]+)#', $input, $matches)) {
            return $matches[1];
        }

        // match: https://youtu.be/4vXkI1zYyDo
        if (preg_match('#//youtu.be/([^\?&"/]+)#', $input, $matches)) {
            return $matches[1];
        }

        return null;
    }
public static function get_youtube_id ( $ input ) { // match: <iframe width="560" height="315" src="https://www.youtube.com/embed/dXxEIZTkqMg" ... // match: https://www.youtube.com/embed/dXxEIZTkqMg if ( preg_match ( '#/embed/([^\?&"]+)#' , $ input , $ matches ) ) { return $ matches [ 1 ] ; } // match: https://www.youtube.com/watch?v=dXxEIZTkqMg&feature=youtu.be // match: https://www.youtube.com/watch?vi=dXxEIZTkqMg&feature=youtu.be if ( preg_match ( '#vi?=([^&]+)#' , $ input , $ matches ) ) { return $ matches [ 1 ] ; } // match: https://youtu.be/4vXkI1zYyDo if ( preg_match ( '#//youtu.be/([^\?&"/]+)#' , $ input , $ matches ) ) { return $ matches [ 1 ] ; } return null ; }
Parses various youtube urls and returns video identifier.

@param string $input The url or the embed code
@return string the url's id
Parses various youtube urls and returns video identifier .