martincorby Posted November 13, 2006 Share Posted November 13, 2006 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 addressif($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>";} }?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 13, 2006 Share Posted November 13, 2006 Yes, we need to see the function. That's the code that seems to be failing.Ken Quote Link to comment Share on other sites More sharing options...
lead2gold Posted November 13, 2006 Share Posted November 13, 2006 can't you just replace all the code in the middle with this?[code]if(ereg("^http://www.mydomain.co.uk$", $row['link_back_address'])){ echo "LINK OK";}else{ echo "BAD LINK";}[/code] Quote Link to comment Share on other sites More sharing options...
martincorby Posted November 13, 2006 Author Share Posted November 13, 2006 Here is the function code<?phpfunction 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;}?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.