A very much novice PHP-er needs help.
I have a function that sits within a Loop, it doesn't seem to like it !
The function tests for a back link from a remote URL to a pre-determined target URL. The function works fine when asked to operate as a stand alone, but put it within a loop of results from the db and I cannot get it to work.
Here is the script. If you need to see the function details let me know.....
<?php
$sql = mysql_query("SELECT * FROM table ORDER BY url ");
while($row = mysql_fetch_array($sql)){
$linkbackaddress=$row['link_back_address'];
$str = substr($linkbackaddress, 1, 1);
//weed out those sites currently without a backlink address
if($str="h"){
if (check_back_link($linkbackaddress, "http://www.mydomain.co.uk")) {
echo $row['url'] . " LINK OK<BR>";
}else{
echo $row['url'] . " LINK BAD<BR>";
}
}else{
echo "No URL to check<BR>";
}
}
?>
Function code :
<?php
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)) {
$found = true;
break;
}
}
fclose($handle);
}
return $found;
}
?>