Forum Moderators: coopster

Message Too Old, No Replies

Identifying off-site links

         

sssweb

8:22 pm on Aug 24, 2006 (gmt 0)

10+ Year Member



Is there an easy way to identify off-site links using php?

For example, on a forum site like webmasterworld.com, I'm looking for code to flag posts that contain:

[yahoo.com...]
www.yahoo.com

while ignoring:

[webmasterworld.com...]
www.webmasterworld.com

and relative URL's like:

/home.htm
/forum/index.php

barns101

10:17 pm on Aug 24, 2006 (gmt 0)

10+ Year Member



Once you've isolated the URL, the following code, using strpos() [uk2.php.net], would work:


$posted_url = 'whatever you find in the post text';
$your_url = 'exmaple.com';
$pos = strpos($mystring, $findme);

if ($pos === false)
{
// It's an outside URL
}
else
{
// It's your URL
}

However, you would need some way to ignore relative links.

sssweb

10:25 pm on Aug 24, 2006 (gmt 0)

10+ Year Member



Using your variables, I assume you mean:

$pos = strpos($posted_url, $your_url);

barns101

12:02 am on Aug 25, 2006 (gmt 0)

10+ Year Member



Yes, sorry! (I used the example from the PHP website but forgot to change that part! ;) )