Jump to content

How to convert all links to "absolute links"


physaux

Recommended Posts

Hi guys, I am getting a page's contents using curl, but I am running into a problem.

 

Some of the links that I find, are "relative links", i.e.

<a href="/about/">About</a>

and I already have the urls extracted in an array as such:

links[0]['url']="/about/";

links[0]['anchor']="/about/";

...

 

My question was, is there any fast way to change "/about/" to "http://mydomain.com/about"?

I tried just appending the link to the current domain, but that becomes a problem if I am say on page:

mydomain.com/index.php  ---->  about.php    ==== mydomain.com/index.phpabout.php

How can I get it to be mydomain.com/about.php??

 

I just need some guide lines, all the ways I have tried are not working. Thank you!!

Link to comment
Share on other sites

If the relative link starts with "/", you can strip the url down to the domain name and then add the relative link.  If it doesn't, then you can remove any filename component at the end of the current url and THEN append it to whatever is left.

 

 

Link to comment
Share on other sites

Well, I think the first poster had the right idea, I want a "operation" to do this effectively. I was just wondering, how could I strip the current url down to the domain? Any ideas how to do that? I'm then going to append with only 1 "/", stripping others if there are more.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.