public function extractYoutubeId($sUrl)
    {
        preg_match('/^https?\:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_\-]+)$/', $sUrl, $aMatches);

        if (!empty($aMatches[1])) {

            return $aMatches[1];

        } else {

            preg_match('/^https?\:\/\/youtu\.be\/([a-zA-Z0-9_\-]+)$/', $sUrl, $aMatches);

            if (!empty($aMatches[1])) {

                return $aMatches[1];
            }
        }

        return null;
    }
public function extractYoutubeId($sUrl)
    {
        preg_match('/^https?\:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_\-]+)$/', $sUrl, $aMatches);

        if (!empty($aMatches[1])) {

            return $aMatches[1];

        } else {

            preg_match('/^https?\:\/\/youtu\.be\/([a-zA-Z0-9_\-]+)$/', $sUrl, $aMatches);

            if (!empty($aMatches[1])) {

                return $aMatches[1];
            }
        }

        return null;
    }
public function extractYoutubeId ( $ sUrl ) { preg_match ( '/^https?\:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_\-]+)$/' , $ sUrl , $ aMatches ) ; if ( ! empty ( $ aMatches [ 1 ] ) ) { return $ aMatches [ 1 ] ; } else { preg_match ( '/^https?\:\/\/youtu\.be\/([a-zA-Z0-9_\-]+)$/' , $ sUrl , $ aMatches ) ; if ( ! empty ( $ aMatches [ 1 ] ) ) { return $ aMatches [ 1 ] ; } } return null ; }
Extracts the ID from a YouTube URL

@param  string $sUrl The YouTube URL

@return string
Extracts the ID from a YouTube URL