physaux Posted January 19, 2010 Share Posted January 19, 2010 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!! Quote Link to comment Share on other sites More sharing options...
btherl Posted January 19, 2010 Share Posted January 19, 2010 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. Quote Link to comment Share on other sites More sharing options...
plznty Posted January 19, 2010 Share Posted January 19, 2010 Do you want /about/ to be about.php if so thats to do with .htaccess If you want an easy way to have actual url you could do this (cheapy idea I know but is a fix) <?php $W = "http://www.example.com"; echo "<a href='$W/about.php'>Link</a>"; ?> Quote Link to comment Share on other sites More sharing options...
physaux Posted January 19, 2010 Author Share Posted January 19, 2010 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. Quote Link to comment Share on other sites More sharing options...
btherl Posted January 20, 2010 Share Posted January 20, 2010 As long as your urls are correctly formed, parse_url() will give you all the individual bits. Then you can paste together the ones you need. I think this function expects them to look like http://domain.com/path/file.html. I'm not sure if it works if you leave out the "http://", for example. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.