Jump to content

Function Failing within Loop


martincorby

Recommended Posts

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']  .  "&nbsp;LINK OK<BR>";
}else{
echo $row['url']  .  "&nbsp;LINK BAD<BR>";
}

}else{
echo "No URL to check<BR>";
}
}
?>
Link to comment
https://forums.phpfreaks.com/topic/27144-function-failing-within-loop/
Share on other sites

Here is the 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;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.