Jump to content

Directory


Pro.Luv

Recommended Posts

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!

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/136076-directory/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/136076-directory/#findComment-709529
Share on other sites

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

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/136076-directory/#findComment-709552
Share on other sites

$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.

Link to comment
https://forums.phpfreaks.com/topic/136076-directory/#findComment-709557
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.