0

I'm parsing HTML files and parsing out the links. Sometimes it comes accross something like:

./dir/dir/lol.html

My question is how do I turn this into an absolute url, the parser knows the URL that if found the link on.

For example:

parses: http://www.website.com/lol/index.html
find: ./dir/dir/haha.html

Then how can I combine this into:

http://www.website.com/lol/dir/dir/haha.html
12
  • you want define a global variable? you can use define function Commented Jun 25, 2012 at 18:54
  • why cant you do a str_replace('href="/','href="http : //www.website.com/',$completePage); on completePage, ignore the spaces in http : //, i kept them intentionally to prevent auto hyperlinking by SO Commented Jun 25, 2012 at 18:55
  • I don't want to define a global variable.. Commented Jun 25, 2012 at 18:55
  • @SwenKooij: It's called relative vs absolute path/url Commented Jun 25, 2012 at 18:56
  • 1
    @Truth, thanks for pointing out the correct words. One search on google helped me finding the answer. Commented Jun 25, 2012 at 18:58

1 Answer 1

1

You could use parse_url() to break URLs into their components most importantly PHP_URL_PATH to find out the path part of the URL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.