How do I use php backlink checker to assign variables?

Discussion in 'PHP' started by bhutastuta, Jan 4, 2009.

  1. #1
    Hi

    I'm very new to php :) and have been learning purely by playing around with existing scripts. However I am not new to coding languages.

    This is what I am trying to do.... I think you'll be able to see just from the code itself what it is I am trying to implement.

    If there is a link back with the anchor text I want then the variable $partner is assigned to "them" otherwise it is assigned to "me".

    $siteurl is defined elsewhere in the rest of the code and will be the website homepage i.e. http:// www. theirdomainname.co.uk

    function check_back_link($remote_url, $your_link,$link_anchor) {
        $match_pattern = preg_quote(rtrim($your_link, "/"), "/");
    	$anchor_pattern = preg_quote(rtrim($link_anchor, "/"), "/");
        $found = false;
        if ($handle = @fopen($remote_url, "r")) {
            while (!feof($handle)) {
                $part = fread($handle, 1024);
                if (preg_match("/<a(.*)href=[\"']".$match_pattern.
    "(\/?)[\"'](.*)>".$anchor_pattern."<\/a>/", $part)) {
                    $found = true;
                    break;
                }
            }
            fclose($handle);
        }
        return $found;
    }
    $pages = array($siteurl."/index.php");
    
    for($i=0;$i<sizeof($pages);$i++){
    	if (!check_back_link($pages[$i], "http://www.mydomainname.co.uk/","Anchor Text"))
           {
    	$partner="me";
    	}
    else
            {
    	$partner = "them";
            }
    }
    PHP:
    It should check that my link is in all of the pages of another website and check that the anchor link is at it should be. If it is the $partner should be assigned to "them", if there is a link breakage then $partner="me".

    Please help.

    Thanks
    Asim
     
    bhutastuta, Jan 4, 2009 IP