I seem to have solved my own problem:
function reltoabs($host, $path) { $resulting = array(); $hostparts = parse_url($host); $pathparts = parse_url($path); if (array_key_exists("host", $pathparts)) return $path; // Absolute // Relative $opath = ""; if (array_key_exists("scheme", $hostparts)) $opath .= $hostparts["scheme"] . "://"; if (array_key_exists("user", $hostparts)) { if (array_key_exists("pass", $hostparts)) $opath .= $hostparts["user"] . ":" . $hostparts["pass"] . "@"; else $opath .= $hostparts["user"] . "@"; } elseif (array_key_exists("pass", $hostparts)) $opath .= ":" . $hostparts["pass"] . "@"; if (array_key_exists("host", $hostparts)) $opath .= $hostparts["host"]; if (!array_key_exists("path", $pathparts) || $pathparts["path"][0] != "/") { $dirname = explode("/", $hostparts["path"]); $opath .= implode("/", array_slice($dirname, 0, count($dirname) - 1)) . "/" . basename($pathparts["path"]); } else $opath .= $pathparts["path"]; if (array_key_exists("query", $pathparts)) $opath .= "?" . $pathparts["query"]; if (array_key_exists("fragment", $pathparts)) $opath .= "#" . $pathparts["fragment"]; return $opath; }
Which seems to work very well, for my purposes.
source share