Jump to content

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

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.