Forum Moderators: coopster

Message Too Old, No Replies

Relative to absolute URL

A problem while page parsing

         

Moby_Dim

4:32 pm on Dec 14, 2016 (gmt 0)

10+ Year Member



Hi!

While parsing w/pages I need to covert relative urls to absolute. I do this with my own functions, but bump into a problem from time to time. At last decided to explore some special functions like parse_url, but found this one isn't perfect too (no wonder but a simple fact ;) )

For example, the parsing page url is 'htt p:/ /www.site.com/NTE/home/en' , the next relative url to resolve among others is 'releases/en' (means href="releases/en")

parse_url dumps the next info about source page url: array(3) { ["scheme"]=> string(4) "htt p" ["host"]=> string(22) "www.site.com" ["path"]=> string(12) "/NTE/home/en" }

and info on the problem url: array(1) { ["path"]=> string(11) "releases/en" }

Actually the target page absolute url is: 'htt p:/ /www.site.com/NTE/releases/en'

And how I should calculate this url using the info above?

Are there any more perfect tools (php functions, scripts) to do this work?

Thank you.

robzilla

5:28 pm on Dec 14, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you noticed they use the <base> tag? Can you grab the value of the href attribute in the <base> tag and put it in front of any relative URL that doesn't begin with a forward slash?

The HTML <base> element specifies the base URL to use for all relative URLs contained within a document. There can be only one <base> element in a document.

[developer.mozilla.org...]

Moby_Dim

7:04 pm on Dec 14, 2016 (gmt 0)

10+ Year Member



oops... Really they do. Forgot about this. Thank you!