public static function parseParams($url_parsed) {

        $vid = FALSE; $url_seperator = FALSE;

        if (preg_match('/^\/watch$/', $url_parsed['path'])) {
            // new Youtube utilizes fragment part instead of query
            $fragment_regex = '/^\!v\=([a-zA-Z0-9]+).*$/';

            if (isset($url_parsed['fragment']) && preg_match($fragment_regex, $url_parsed['fragment'])) {

                $vid = preg_replace($fragment_regex, '$1', $url_parsed['fragment']);
                $url_seperator = '#!';

            } else {

                // parse fragment parameters into query string
                if (!empty($url_parsed['fragment'])) {
                    if (!empty($url_parsed['query'])) {
                        $url_parsed['query'] = $url_parsed['query'].'&'.$url_parsed['fragment'];
                    } else {
                        $url_parsed['query'] = $url_parsed['fragment'];
                    }
                }

                // backward compatibility
                parse_str($url_parsed['query'], $args);
                if (isset($args['v'])) {
                    $vid = $args['v'];
                    $t = isset($args['t']) ? $args['t'] : '';
                    $t_fragment = !empty($t) ? '&t='.$t : '';
                    $url_seperator = '?';
                }

            }

            $location = preg_replace('/([a-z]+?)\.youtube\.com/', '$1', strtolower($url_parsed['host']));
            $string = 'http://'.$location.'.youtube.com/watch'.$url_seperator.'v='.$vid.$t_fragment;
        } elseif (preg_match('/^\/user\/[a-zA-Z0-9_\-]+$/',  $url_parsed['path'])){
            $fragment_regex = '/^p\/u\/[0-9]+\/([a-zA-Z0-9]+)/';
            if (preg_match($fragment_regex, $url_parsed['fragment'])) {
                $vid = preg_replace($fragment_regex, '$1', $url_parsed['fragment']);
            }

            $location = preg_replace('/([a-z]+?)\.youtube\.com/', '$1', strtolower($url_parsed['host']));
            $string = 'http://'.$url_parsed['host'].'/'.$url_parsed["path"].'#'.$url_parsed['fragment'];
        }


        return ($vid === FALSE) ? FALSE : array(
            'vid'           => $vid,
            'url_seperator' => $url_seperator,
            'location'      => $location,
            'string'        => $string,
            't'             => $t,
        );
    }
public static function parseParams($url_parsed) {

        $vid = FALSE; $url_seperator = FALSE;

        if (preg_match('/^\/watch$/', $url_parsed['path'])) {
            // new Youtube utilizes fragment part instead of query
            $fragment_regex = '/^\!v\=([a-zA-Z0-9]+).*$/';

            if (isset($url_parsed['fragment']) && preg_match($fragment_regex, $url_parsed['fragment'])) {

                $vid = preg_replace($fragment_regex, '$1', $url_parsed['fragment']);
                $url_seperator = '#!';

            } else {

                // parse fragment parameters into query string
                if (!empty($url_parsed['fragment'])) {
                    if (!empty($url_parsed['query'])) {
                        $url_parsed['query'] = $url_parsed['query'].'&'.$url_parsed['fragment'];
                    } else {
                        $url_parsed['query'] = $url_parsed['fragment'];
                    }
                }

                // backward compatibility
                parse_str($url_parsed['query'], $args);
                if (isset($args['v'])) {
                    $vid = $args['v'];
                    $t = isset($args['t']) ? $args['t'] : '';
                    $t_fragment = !empty($t) ? '&t='.$t : '';
                    $url_seperator = '?';
                }

            }

            $location = preg_replace('/([a-z]+?)\.youtube\.com/', '$1', strtolower($url_parsed['host']));
            $string = 'http://'.$location.'.youtube.com/watch'.$url_seperator.'v='.$vid.$t_fragment;
        } elseif (preg_match('/^\/user\/[a-zA-Z0-9_\-]+$/',  $url_parsed['path'])){
            $fragment_regex = '/^p\/u\/[0-9]+\/([a-zA-Z0-9]+)/';
            if (preg_match($fragment_regex, $url_parsed['fragment'])) {
                $vid = preg_replace($fragment_regex, '$1', $url_parsed['fragment']);
            }

            $location = preg_replace('/([a-z]+?)\.youtube\.com/', '$1', strtolower($url_parsed['host']));
            $string = 'http://'.$url_parsed['host'].'/'.$url_parsed["path"].'#'.$url_parsed['fragment'];
        }


        return ($vid === FALSE) ? FALSE : array(
            'vid'           => $vid,
            'url_seperator' => $url_seperator,
            'location'      => $location,
            'string'        => $string,
            't'             => $t,
        );
    }
public static function parseParams ( $ url_parsed ) { $ vid = FALSE ; $ url_seperator = FALSE ; if ( preg_match ( '/^\/watch$/' , $ url_parsed [ 'path' ] ) ) { // new Youtube utilizes fragment part instead of query $ fragment_regex = '/^\!v\=([a-zA-Z0-9]+).*$/' ; if ( isset ( $ url_parsed [ 'fragment' ] ) && preg_match ( $ fragment_regex , $ url_parsed [ 'fragment' ] ) ) { $ vid = preg_replace ( $ fragment_regex , '$1' , $ url_parsed [ 'fragment' ] ) ; $ url_seperator = '#!' ; } else { // parse fragment parameters into query string if ( ! empty ( $ url_parsed [ 'fragment' ] ) ) { if ( ! empty ( $ url_parsed [ 'query' ] ) ) { $ url_parsed [ 'query' ] = $ url_parsed [ 'query' ] . '&' . $ url_parsed [ 'fragment' ] ; } else { $ url_parsed [ 'query' ] = $ url_parsed [ 'fragment' ] ; } } // backward compatibility parse_str ( $ url_parsed [ 'query' ] , $ args ) ; if ( isset ( $ args [ 'v' ] ) ) { $ vid = $ args [ 'v' ] ; $ t = isset ( $ args [ 't' ] ) ? $ args [ 't' ] : '' ; $ t_fragment = ! empty ( $ t ) ? '&t=' . $ t : '' ; $ url_seperator = '?' ; } } $ location = preg_replace ( '/([a-z]+?)\.youtube\.com/' , '$1' , strtolower ( $ url_parsed [ 'host' ] ) ) ; $ string = 'http://' . $ location . '.youtube.com/watch' . $ url_seperator . 'v=' . $ vid . $ t_fragment ; } elseif ( preg_match ( '/^\/user\/[a-zA-Z0-9_\-]+$/' , $ url_parsed [ 'path' ] ) ) { $ fragment_regex = '/^p\/u\/[0-9]+\/([a-zA-Z0-9]+)/' ; if ( preg_match ( $ fragment_regex , $ url_parsed [ 'fragment' ] ) ) { $ vid = preg_replace ( $ fragment_regex , '$1' , $ url_parsed [ 'fragment' ] ) ; } $ location = preg_replace ( '/([a-z]+?)\.youtube\.com/' , '$1' , strtolower ( $ url_parsed [ 'host' ] ) ) ; $ string = 'http://' . $ url_parsed [ 'host' ] . '/' . $ url_parsed [ "path" ] . '#' . $ url_parsed [ 'fragment' ] ; } return ( $ vid === FALSE ) ? FALSE : array ( 'vid' => $ vid , 'url_seperator' => $ url_seperator , 'location' => $ location , 'string' => $ string , 't' => $ t , ) ; }
helper function
extract video id and other parameters from url
@param string[] $url_parsed result of parse_url($url)
helper function extract video id and other parameters from url