Connecting Tech Pros Worldwide Help | Site Map

Combining an absolute and relative Url

  #1  
Old July 17th, 2005, 03:20 AM
Joe Cybernet
Guest
 
Posts: n/a
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


  #2  
Old July 17th, 2005, 03:20 AM
CountScubula
Guest
 
Posts: n/a

re: Combining an absolute and relative Url


"Joe Cybernet" <no@no.ie> wrote in message
news:O3jLb.4067$HR.8512@news.indigo.ie...[color=blue]
> Is there any function for combining an absolute and a relative URL to[/color]
result[color=blue]
> in an absolute URL?
> Like if I have http://www.domain.com and "../images/1.jpeg" it will[/color]
evaluate[color=blue]
> 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
>
>[/color]


strAbs = strDom & strURI

--
Mike Bradley
http://www.gzentools.com -- free online php tools


  #3  
Old July 17th, 2005, 03:20 AM
CountScubula
Guest
 
Posts: n/a

re: Combining an absolute and relative Url


"Joe Cybernet" <no@no.ie> wrote in message
news:O3jLb.4067$HR.8512@news.indigo.ie...[color=blue]
> Is there any function for combining an absolute and a relative URL to[/color]
result[color=blue]
> in an absolute URL?
> Like if I have http://www.domain.com and "../images/1.jpeg" it will[/color]
evaluate[color=blue]
> 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
>
>[/color]
oops, I thought I was in the comp.lang.basic.visual, direagard my last post

$absURL = $dom . $URI;

--
Mike Bradley
http://www.gzentools.com -- free online php tools


  #4  
Old July 17th, 2005, 03:20 AM
Chung Leong
Guest
 
Posts: n/a

re: Combining an absolute and relative Url


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:O3jLb.4067$HR.8512@news.indigo.ie...[color=blue]
> Is there any function for combining an absolute and a relative URL to[/color]
result[color=blue]
> in an absolute URL?
> Like if I have http://www.domain.com and "../images/1.jpeg" it will[/color]
evaluate[color=blue]
> 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
>
>[/color]


  #5  
Old July 17th, 2005, 03:21 AM
John Dunlop
Guest
 
Posts: n/a

re: Combining an absolute and relative Url


Joe Cybernet wrote:
[color=blue]
> Is there any function for combining an absolute and a relative URL to result
> in an absolute URL?[/color]

As has already been said, there isn't a built-in function for
resolving relative URLs. However, you might follow the algorithm set
out in RFC2396 sec. 5.2. Watch out if you're using parse_url, as it
parses some relative URLs incorrectly.

--
Jock
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Padding(Margin?) Issues in Firefox sllrphoto@yahoo.com answers 11 October 28th, 2006 10:35 PM
120 DPI & HTML text woes Yeah answers 7 March 3rd, 2006 10:35 PM
Lots of confusion on SSL CW answers 0 November 18th, 2005 10:22 AM