public static function url_parser($url)
    {
        $regex = '/(?<=v=|v\/|vi=|vi\/|youtu.be\/|embed\/)([a-zA-Z0-9_-]{11})/';

        if (!empty($url)) {
            //full youtube URL
            if (strpos($url, 'youtu') !== false) {
                if (preg_match($regex, $url, $matches)) {
                    return $matches[1];
                }
            } elseif (strlen($url) == 11) {
                return $url;
            }
        }

        return false;
    }
public static function url_parser($url)
    {
        $regex = '/(?<=v=|v\/|vi=|vi\/|youtu.be\/|embed\/)([a-zA-Z0-9_-]{11})/';

        if (!empty($url)) {
            //full youtube URL
            if (strpos($url, 'youtu') !== false) {
                if (preg_match($regex, $url, $matches)) {
                    return $matches[1];
                }
            } elseif (strlen($url) == 11) {
                return $url;
            }
        }

        return false;
    }
public static function url_parser ( $ url ) { $ regex = '/(?<=v=|v\/|vi=|vi\/|youtu.be\/|embed\/)([a-zA-Z0-9_-]{11})/' ; if ( ! empty ( $ url ) ) { //full youtube URL if ( strpos ( $ url , 'youtu' ) !== false ) { if ( preg_match ( $ regex , $ url , $ matches ) ) { return $ matches [ 1 ] ; } } elseif ( strlen ( $ url ) == 11 ) { return $ url ; } } return false ; }
Parse YouTube URL into a valid 11-character ID.

@param $url string Valid YouTube URL or ID.

@return string|false YouTube Video ID, or false if no ID found
Parse YouTube URL into a valid 11 - character ID .