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
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;
}

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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