brooksh Posted March 13, 2007 Share Posted March 13, 2007 How can I verify that my link exists on another site? I want to search the page and for the script to come back and say that it is there or not. $handle = fopen("$url", "rb"); $contents = 'mylink.com'; while (!feof($handle)) { $contents .= fread($handle, 8192); } if($contents!=""){ echo "No"; } else { echo "Yes"; fclose($handle); Link to comment https://forums.phpfreaks.com/topic/42562-solved-verify-that-link-exists/ Share on other sites More sharing options...
flann Posted March 13, 2007 Share Posted March 13, 2007 you could use a regular expression that checks to see if your link is on the page. There are lots of these on the web to validate links. Link to comment https://forums.phpfreaks.com/topic/42562-solved-verify-that-link-exists/#findComment-206544 Share on other sites More sharing options...
boo_lolly Posted March 13, 2007 Share Posted March 13, 2007 what seems to be the problem so far? is it returning an error? btw, i'm not positive, but i believe there is a limit to the characters fread() can handle. i believe it's 1024, which means it will only read 1023 characters. Link to comment https://forums.phpfreaks.com/topic/42562-solved-verify-that-link-exists/#findComment-206548 Share on other sites More sharing options...
brooksh Posted March 13, 2007 Author Share Posted March 13, 2007 <?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; } // example: //if (check_back_link("http://www.it-guru.co.uk", "http://www.it-guru.co.uk")) echo "link exists"; ?> Link to comment https://forums.phpfreaks.com/topic/42562-solved-verify-that-link-exists/#findComment-206563 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.