Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 03:20 AM
Joe Cybernet
Guest
 
Posts: n/a
Default Combining an absolute and relative Url

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
Default 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
Default 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
Default 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
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.