User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,571 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,719 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Feb 14th, 2006
Views: 2,391
This function is usefull for peoples with a link directory where the links are stored inside a (MySQL) database. The PHP script is easy to use to find out if a reciprocal link still exists on the corresponding webpage. It takes care about the trailing slash in urls and can be used with (almost) every url. Inside the function is a check against a regular expression pattern and the result is a simple boolean. Check the example here
php Syntax | 5 stars
  1. <?php
  2. function check_back_link($remote_url, $your_link) {
  3. $match_pattern = preg_quote(rtrim($your_link, "/"), "/");
  4. $found = false;
  5. if ($handle = @fopen($remote_url, "r")) {
  6. while (!feof($handle)) {
  7. $part = fread($handle, 1024);
  8. if (preg_match("/<a(.*)href=[\"']".$match_pattern.
  9. "(\/?)[\"'](.*)>(.*)<\/a>/", $part)) {
  10. $found = true;
  11. break;
  12. }
  13. }
  14. fclose($handle);
  15. }
  16. return $found;
  17. }
  18. // example:
  19. //if (check_back_link("http://www.all4yourwebsite.com", "http://www.finalwebsites.com")) echo "link exists";
  20. ?>
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 5:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC