bigrollerdave
Feb 6th 2008, 12:02 pm
I've stated this a few times but I really suck with preg_match's I can't seem to learn them for some reason. Anyways, below is a simple php function to check to see if a backlink exists on another site and it will also check to see if there is a nofollow tag. The script works fine with the backlink is something like thsi
http://www.domain.com
but if the backlink on the other site is like this
http://www.domain/com/page1.php
The script will say no link exists. How can I edit the code to check to see if just
http://www.domain.com
exists on the site and then dismiss anything that may come after the that?
function check_back_link($remote_url, $your_link) {
$match_pattern = preg_quote(rtrim($your_link, "/"), "/");
$found = false;
if ($handle = @fopen($remote_url, "r")) {
while (!feof($handle)) {
$part = fread($handle, 1024);
if (preg_match("/<a(.*)href=[\"']".$match_pattern."(\/?)[\"'](.*)>(.*)<\/a>/", $part, $match)) {
if (preg_match("/rel=[\"']?nofollow[\"']?/", $match[0]))
$found = false;
else
$found = true;
break;
}
}
fclose($handle);
}
return $found;
}
Sorry it that's a little confusing I tried to explain it the best I could.
Thansk
http://www.domain.com
but if the backlink on the other site is like this
http://www.domain/com/page1.php
The script will say no link exists. How can I edit the code to check to see if just
http://www.domain.com
exists on the site and then dismiss anything that may come after the that?
function check_back_link($remote_url, $your_link) {
$match_pattern = preg_quote(rtrim($your_link, "/"), "/");
$found = false;
if ($handle = @fopen($remote_url, "r")) {
while (!feof($handle)) {
$part = fread($handle, 1024);
if (preg_match("/<a(.*)href=[\"']".$match_pattern."(\/?)[\"'](.*)>(.*)<\/a>/", $part, $match)) {
if (preg_match("/rel=[\"']?nofollow[\"']?/", $match[0]))
$found = false;
else
$found = true;
break;
}
}
fclose($handle);
}
return $found;
}
Sorry it that's a little confusing I tried to explain it the best I could.
Thansk