public function get_current_url() { $current_url = new HTMLTags_URL(); if ($_SERVER['HTTPS']) { $current_url->set_scheme('https'); } else { $current_url->set_scheme('http'); } if (preg_match('/([-\\w.]+):(\\d+)/', $_SERVER['HTTP_HOST'], $matches)) { $current_url->set_domain($matches[1]); $current_url->set_port($matches[2]); } else { $current_url->set_domain($_SERVER['HTTP_HOST']); } $file = $_SERVER['REQUEST_URI']; if (preg_match('/(.*)\\?/', $file, $matches)) { $file = $matches[1]; } $current_url->set_file($file); foreach (array_keys($_GET) as $get_var_key) { $current_url->set_get_variable($get_var_key, $_GET[$get_var_key]); } return $current_url; }
/** * Parse a URL string and create an object. * * It makes more sense for this to be a static factory function * like this that the method above. */ public static function parse_and_make_url($url_str) { $url = new HTMLTags_URL(); #echo "\$url_str: $url_str\n"; /* * Is the scheme set? */ if (preg_match('{^([a-zA-Z]+)://(.+)}', $url_str, $matches)) { $url->set_scheme($matches[1]); $url_without_scheme_and_punc = $matches[2]; if (preg_match('{^([^/]+)(.+)}', $url_without_scheme_and_punc, $matches)) { $url->set_domain($matches[1]); $url_str = $matches[2]; } } if (preg_match('{([^?]*)(?:\\?((?:[^=]+=[^=&]+)(?:&[^=]+=[^=&]+)*))?}', $url_str, $matches)) { #echo 'print_r($matches): ' . "\n"; #print_r($matches); $file = $matches[1]; if (isset($matches[2])) { $get_vars = $matches[2]; } else { $get_vars = NULL; } $url->set_file($file); foreach (explode('&', $get_vars) as $key_value_pair) { if (preg_match('/([^=]+)=([^=]+)/', $key_value_pair, $matches)) { $url->set_get_variable($matches[1], $matches[2]); } } } #print_r($url); # #exit; return $url; }