473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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
Jul 17 '05 #1
4 9113
"Joe Cybernet" <no@no.ie> wrote in message
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

strAbs = strDom & strURI

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #2
"Joe Cybernet" <no@no.ie> wrote in message
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

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
Jul 17 '05 #3
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

Jul 17 '05 #4
Joe Cybernet wrote:
Is there any function for combining an absolute and a relative URL to result
in an absolute URL?


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
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Stuart | last post by:
Hi All, I got a challenge to make the same APS/Script/Html run on different web roots. I can not use relative pathing in a lot of cases. We use lots of included files so depending on where that...
4
by: Vitali Gontsharuk | last post by:
Hallo! When using the XPATH document() function to load a new XML document, we are coming across problems, because XALAN seems to have problems with absolute paths. XALAN always assumes that the...
7
by: Alex | last post by:
Hi Everone, I need some advice on how to setup 4 columns where the outside two are absolute (120px) and the inner two (side by side) are relevent (Fluid) and change with the screen. Here's my...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
4
by: Amir Eshterayeh | last post by:
Dear Friends My asp hyperlink goes to relative address instead of absolute. I like navigate url goes to outsite link like www.asp.net but now, it goes to www.mysite/www.asp.net please help....
2
by: Turbo | last post by:
How to get absolute uri by combining the baseuri and the relative uri in an html page using javscript? I am looking for something similar to python's urlparse.urljoin('baseuri', 'relativeuri');...
1
by: GGG | last post by:
Neither go the way I want them to... Absolute doesn't get it right over multiple browsers. Relative puts it in the right place, but only the portion that it is "relative" the style, #wleMenu, is...
6
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I...
13
by: Nathan Sokalski | last post by:
I have a page in my site that I need the absolute url of. Is there a function in .NET to which you can pass a relative url or something such as "~/mydirectory/mypage.aspx" which will return an...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.