There's no built-in function that does that. Here's one that should join
there correctly:
function InternetCombineUrl($absolute, $relative) {
extract(parse_url($absolute));
if($relative{0} == '/') {
$cparts = array_filter(explode("/", $relative));
}
else {
$aparts = array_filter(explode("/", $path));
$rparts = array_filter(explode("/", $relative));
$cparts = array_merge($aparts, $rparts);
foreach($cparts as $i => $part) {
if($part == '.') {
$cparts[$i] = null;
}
if($part == '..') {
$cparts[$i - 1] = null;
$cparts[$i] = null;
}
}
$cparts = array_filter($cparts);
}
$path = implode("/", $cparts);
$url = "";
if($scheme) {
$url = "$scheme://";
}
if($user) {
$url .= "$user";
if($pass) {
$url .= ":$pass";
}
$url .= "@";
}
if($host) {
$url .= "$host/";
}
$url .= $path;
return $url;
}
echo InternetCombineUrl("http://www.domain.com", "../images/1.jpeg");
Uzytkownik "Joe Cybernet" <no@no.ie> napisal w wiadomosci
news:O3****************@news.indigo.ie...
Is there any function for combining an absolute and a relative URL to
result in an absolute URL?
Like if I have http://www.domain.com and "../images/1.jpeg" it will
evaluate to http://www.domain.com/images/1.jpeg.
I know WinInet for windows has a function that does this called
InternetCombineUrl, I just need the same function in PHP