28 list($abs_uri, $base) = self::normalize(array($abs_uri, $base));
31 if (!preg_match(
'/\/$/', $base)) {
34 $abs_array = explode(
'/', $abs_uri);
35 $base_array = explode(
'/', $base);
39 if (strrpos($abs_uri,
'/') !== strlen($abs_uri)) {
40 $fileName = array_pop($abs_array);
42 if (strrpos($base,
'/') !== strlen($base)) {
43 array_pop($base_array);
47 while (
sizeof($abs_array) > 0 &&
sizeof($base_array) > 0 && $abs_array[0] == $base_array[0]) {
48 array_shift($abs_array);
49 array_shift($base_array);
53 $rel_uri = str_repeat(
'../',
sizeof($base_array)).join(
'/', $abs_array).
'/'.$fileName;
64 list($rel_uri, $base) = self::normalize(array($rel_uri, $base));
66 if(strpos($rel_uri,
"//") === 0) {
67 return "http:".$rel_uri;
70 if (parse_url($rel_uri, PHP_URL_SCHEME) !=
'') {
74 if (!preg_match(
'/\/$/', $base)) {
77 $firstChar = (strlen($rel_uri) > 0) ? substr($rel_uri, 0, 1) :
'';
79 if ($firstChar ==
'#' || $firstChar ==
'?') {
80 return $base.$rel_uri;
83 extract(parse_url($base));
84 $scheme = !isset($scheme) ?
'http' : $scheme;
85 $host = !isset($host) ?
'' : $host;
86 $path = !isset($path) ?
'' : $path;
88 $path = preg_replace(
'#/[^/]*$#',
'', $path);
90 if ($firstChar ==
'/') {
94 $abs =
"$host$path/$rel_uri";
96 $re = array(
'#(/\.?/)#',
'#/(?!\.\.)[^/]+/\.\./#');
97 for ($n=1; $n>0; $abs=preg_replace($re,
'/', $abs, -1, $n)) {}
99 return $scheme.
'://'.$abs;
113 list($rel_uri, $base) = self::normalize(array($rel_uri, $base));
115 $self = self::getProtocolStr().$_SERVER[
'HTTP_HOST'].$_SERVER[
'SCRIPT_NAME'];
116 $path = dirname($self).
'/';
117 $absUrl = self::makeAbsolute($rel_uri, $path.$base);
118 $relUrl = self::makeRelative($absUrl, $path);
120 return array(
'absolute' => $absUrl,
'relative' => $relUrl);
131 $url_parts = @parse_url($url);
133 if (empty($url_parts[
"host"])) {
134 $fh = @fopen($url,
"r");
135 return ($fh !==
false);
140 curl_setopt($ch, CURLOPT_URL, $url);
141 curl_setopt($ch, CURLOPT_HEADER,
true);
142 curl_setopt($ch, CURLOPT_NOBODY,
true);
143 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
144 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
146 $headers = split(
"\n", $r);
148 preg_match(
'/.+ ([0-9]{3}) .+/', $headers[0], $matches);
149 return (intval($matches[1]) < 400);
157 if (isset($_SERVER[
'HTTPS']) && strlen($_SERVER[
'HTTPS']) > 0 && $_SERVER[
'HTTPS'] !=
'off') {
170 $pageURL = self::getProtocolStr();
171 if ($_SERVER[
"SERVER_PORT"] !=
"80") {
172 $pageURL .= $_SERVER[
"SERVER_NAME"].
":".$_SERVER[
"SERVER_PORT"].$_SERVER[
"REQUEST_URI"];
175 $pageURL .= $_SERVER[
"SERVER_NAME"].$_SERVER[
"REQUEST_URI"];
186 array(
"/\\\\/",
"/^[^:]{1}:/", ), array(
'/',
''),
static translate($rel_uri, $base)
Translate a relative URI from one location to the script location.
static validateUrl($url, $timeout=5)
Check if an url is available (HTTP-Code: 200)
static getPageURL()
Get the current page url.
static makeRelative($abs_uri, $base)
Convert an absolute URI to a relative code from http://www.webmasterworld.com/forum88/334.htm.
static normalize($paths)
Normalize slashes and remove drive names.
static makeAbsolute($rel_uri, $base)
Convert a relative URI to an absolute code from http://99webtools.com/relative-path-into-absolute-url...
URIUtil provides support for uri manipulation.