将远程相对路径转换为绝对路径

我尝试寻找类似的问题,但未能成功.

I tried looking for a similar question, but was unable to.

我正在寻找正确的方向.我目前正在做的是 现在可以收集远程站点的所有href值的列表,因为其中一些可以 相对路径,我需要一个构建绝对路径的函数.

I'm looking for push in the right direction. What I'm currently doing is gathering a list of all href values of a remote site, now since some of them can be relative paths, I need a function that builds an absolute path.

由于我拥有域名(通过遵循使用的最后一个URL cUrl):

Since I have the domain name (by following the last url cUrl used):

$base_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

现在,假设$ base_url的值为: http://www.example.com/home/index.html 我当前正在读取的href值为:/styles/ie.css

Now lets say $base_url value is: http://www.example.com/home/index.html and href value I'm currently reading is: /styles/ie.css

我需要将$ base_url的值更改为 http://www.example.com/样式/ie.css 但是我需要该功能尽可能地动态.看看 可能的情况(可能不是全部):

I need to turn the value of $base_url to http://www.example.com/styles/ie.css but I need that function to be dynamic as much as possible. Take a look at the possible scenarios (probably a not all):

1 = base url
2 = relative path
------------------------------------------------
1 http://www.example.com/
2 java/popups.js

1 + 2 = http://www.example.com/java/popups.js
------------------------------------------------
1 http://www.example.com
2 java/popups.js

1 + / + 2 = http://www.example.com/java/popups.js
------------------------------------------------
1 http://www.example.com/mysite/
2 ../java/popups.js 

1 - / + (2 - ..) = http://www.example.com/java/popups.js
------------------------------------------------

1 http://www.example.com/rsc/css/intlhplib-min.css
2 ../images/sunflower.png

1 - /css/intlhplib-min.css + (2 - ..) = http://www.example.com/rsc/images/sunflower.png     



 1 条回答