note 49601 added to function.preg-match-all

From: Date: Wed, 02 Feb 2005 18:41:53 +0000
Subject: note 49601 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-84384@lists.php.net to get a copy of this message
Here is a handy function I wrote that will check for broken links on the supplied url. function dead_links($url) { // mixed link_checker( $url ) // Returns: // FALSE if no broken links are found. // ARRAY containing broken links if any are found. ob_start(); if( !readfile($url) ) return FALSE; $body = ob_get_contents(); ob_end_clean(); $pathparts = pathinfo($url); $urlpattern = "/<a[^>]+href=\"([^\"]+)/i"; preg_match_all($urlpattern,$body,$matches); foreach( $matches[1] as $link) { if( strpos($link,"http://") === FALSE ) { // Deal with relative paths $link = $pathparts['dirname'] . "/" . $link; } $fp = @fopen("$link", "r"); fclose($fp); if (!$fp) { $linkArray[] = $link; } } return (is_array($linkArray) ) ? $linkArray : FALSE; } Regards, Michael Bourque ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49601 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49601&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49601&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49601&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49601&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49601&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49601&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84384) next »