/** * Get absolute URL * * PHP Extension * * @access public * @static * @param string $base base url * @param string $url relative url * @return string absolute url * @see parse_url() * @see realpath() * @uses glue_url() * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $ */ function realurl($base, $url) { if (!strlen($base)) { return $url; } if (!strlen($url)) { return $base; } if (preg_match('!^[a-z]+:!i', $url)) { return $url; } $base = parse_url($base); if ($url[0] == "#") { // fragment $base['fragment'] = substr($url, 1); return sonots::glue_url($base); } unset($base['fragment']); unset($base['query']); if (substr($url, 0, 2) == "//") { // FQDN $base = array('scheme' => $base['scheme'], 'path' => substr($url, 2)); return sonots::glue_url($base); } elseif ($url[0] == "/") { // absolute path reference $base['path'] = $url; } else { // relative path reference $path = explode('/', $base['path']); $url_path = explode('/', $url); // drop file from base array_pop($path); // append url while removing "." and ".." from // the directory portion $end = array_pop($url_path); foreach ($url_path as $segment) { if ($segment == '.') { // skip } elseif ($segment == '..' && $path && $path[sizeof($path) - 1] != '..') { array_pop($path); } else { $path[] = $segment; } } // remove "." and ".." from file portion if ($end == '.') { $path[] = ''; } elseif ($end == '..' && $path && $path[sizeof($path) - 1] != '..') { $path[sizeof($path) - 1] = ''; } else { $path[] = $end; } $base['path'] = join('/', $path); } return sonots::glue_url($base); }