Pro.Luv Posted December 8, 2008 Share Posted December 8, 2008 Hi, I need to get the full address of links if a link is: <a href="page.htm"> Page </a> How can I get the full address of that link so that it looks like: http://www.website.com/page.htm And if a link is like: <a href="/page1.htm"> Page </a> how can I get the address like http://www.website.com/page1.htm Really need help with this thanks! Quote Link to comment https://forums.phpfreaks.com/topic/136076-directory/ Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 Are the links on your website or someone elses? If someone elses, you just need to know the domain name then append it. If yours, use $_SERVER['HTTP_HOST'] to print out the server name, or define it in your script as a constant. If neither please be more descriptive of the problem. Quote Link to comment https://forums.phpfreaks.com/topic/136076-directory/#findComment-709529 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 You could try something like this; echo "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; Quote Link to comment https://forums.phpfreaks.com/topic/136076-directory/#findComment-709538 Share on other sites More sharing options...
Pro.Luv Posted December 8, 2008 Author Share Posted December 8, 2008 Hi premiso, It's on someone elses... Could you show me code when you say... If someone elses, you just need to know the domain name then append it. I would really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/136076-directory/#findComment-709542 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 Ok there are about 5 different options here. How exactly are you using this script? As I do not feel like writing out all 5 different options and find out it was option 6 all along. Quote Link to comment https://forums.phpfreaks.com/topic/136076-directory/#findComment-709545 Share on other sites More sharing options...
Pro.Luv Posted December 8, 2008 Author Share Posted December 8, 2008 Okay.. I have something like this: eg. $value = <a href="http://www.website.com/link.htm">Link 1</a> if (ereg ("(^http|^https)", $value, $regs)){ print($value."<br />"); } This just match's if the link start's with HTTP or HTTPS, if it does then print it out, I sometimes come across links that are like: <a href="page.htm"> Page </a> AND <a href="/page1.htm"> Page </a> So I want to also print out those links but I need to get the full address I would then change this.. if (ereg ("(^http|^https|^/|^)", $value, $regs)){ print($value."<br />"); } Correct me if I'm mistaken Quote Link to comment https://forums.phpfreaks.com/topic/136076-directory/#findComment-709552 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 $fetchedDomain = "http://www.website.com/"; if (ereg ("(^http|^https|^/|^)", $value, $regs)){ $value = $fetchedDomain . str_replace("/", "", $value); echo $value; } Something like that would do the trick, you just have to know the domain name you are fetching. Quote Link to comment https://forums.phpfreaks.com/topic/136076-directory/#findComment-709557 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.