All pastes #30856 Raw Edit

Unnamed

public php v1 · immutable
#30856 ·published 2005-11-24 05:08 UTC
rendered paste body
<?php/* tools to spider through hyperlinks *//*function search($origin, $prefix, $pattern, $threshhold) {	/* spiders through $threshhold deep pages from $originUrl, constrained by $prefix, returning all regex matches for $pattern */function StrStartsWith(& $str, $start) {	 /* Determines if a string $str starts with $start */	return (substr($str, 0, strlen($start)) == $start);}function hyperlinks ($page) {	/* returns all hyperlinks from string $page */	preg_match_all('/<a href=".+".*<\/a>/i', $page, $matches);	return ($matches);}function domainFromHyperlink ($hyperlink) {	/* returns the domain name from $hyperlink, or false if there is none */	$pattern = "/(<a href=\")(.+\.[a-z]{2,5})(.*<\/a>)/i"; /* regex for domain from a hyperlink */	if (!preg_match($pattern, $hyperlink, $matches)) {		return (false);	} else {		return ($matches);	}}function crawl ($origin, $hostPrison) {	/* recursive. returns an array of urls. won't get urls that arent on domain $host, if set */	foreach (hyperlinks(file_get_contents($origin)) as $link) {		if (isset($hostPrison)) {			/* check if hostPrison occurs within origin				eg hostPrison="foo.com", origin="http://foo.com/bar.html" would satisfy this condition */						if (!strpos($origin, $hostPrison === false)) {				$urls[] = crawl($link); // $urls[] = crawl($link);			}		} else { /* executed if $hostPrison is unset */			$urls[] = crawl($link); // $urls[] = crawl($link);		}	}	unset ($hostPrison);	return ($urls);}echo '<textarea rows=25 cols=100>';$testmatches = hyperlinks (file_get_contents("linktest.html"));print_r($testmatches);echo '</textarea> <hr /><textarea rows=25 cols=100>';foreach ($testmatches as $testmatch) {	foreach ($testmatch as $match) {		var_dump($match);		echo (domainFromHyperlink ($match));	}}echo '</textarea>';//echo 'test';?>