Forum Moderators: coopster

Message Too Old, No Replies

comparing a url string

making it more flexible

         

chrisandsarah

11:32 am on Jan 19, 2004 (gmt 0)

10+ Year Member



Hi i'm no php programmer but a big part of my site now uses it after i payed someone to automate alot of it.
However, now ive spotted a problem.
I have a link exchange script which searches another sites url to make sure my link is present before it automatically adds their link.
I've noticed though that if the url they use is a level deeper than the one it looks for, the script cant find it. I need to make it more flexible. Can anyone help?

This is the script part that i *think* looks for my url on their page:

function check_link($str)
{
$lookup = <<<ERT
<a href="http://www.mydomain.com/">
ERT;
if (strpos(@implode("\r",@file($str)),$lookup)){
return 1;
} else {
return 0;
}
}

------------------
If the link they use is e.g [mydomain.com...]
the script wont find it. Does anyone know how i can make it accept a url aslong is it contains my domain in part of it?

Many thanks if you can help..

BitBanger

3:03 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



Well I can make it better quite easily, but even with the change it is still possible to miss some links. Change the code to:

function check_link($str)
{
$lookup = <<<ERT
<a href="http://www.mydomain.com/
ERT;
if (strpos(@implode("\r",@file($str)),$lookup)){
return 1;
} else {
return 0;
}
}

What I did was to remove the "> from the end of your URL. This will make it match

http://www.mydomain.com/keyword/
as you desire. However, what it won't do is to find your link if the other site uses any other form of anchor. For example, if the link is written as
<a class="some_class_name" href="http://www.mydomain.com/">
this script won't find the link. (and wouldn't before either)

chrisandsarah

4:09 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



Thanks. Ive just adjusted it as you said and tested it and it works great. That gets round my main problem.
Thanks for your help