Tutorial: Matchy Matchy Research Script

I always think that there is a programming solution to most tedious tasks. In this example, I have a client with a list of 300 members who want a compiled list of online mentions of their members. The traditional method would be to maybe search each page 300 times and look for each member. A slightly better method would be to combine all the pages you're searching in to make one long page and then search that page. But better would be to write a script that loops through the list and searches the page for you and only shows the matches.

The script is pretty short, but with a bit more time I could take this information and dump it into a database, or loop through many different pages, or even find and follow href links on the first page and let this script find its own pages and email me the results when it's done.

// $list is the array of member names
$lnum=count($list);
// gather pages of results
$fh=fopen('http://www.winningtime.ca/09/
09fhhm/agegroup.txt','r');

while(!feof($fh)){
	// get a line
	$oneline=htmlspecialchars(fgets($fh,1024));
	// does it match to array
	for($i=0; $i<$lnum; $i++){
	   $c=trim($list[$i]);
	   if(eregi($c,$oneline)){
		echo "$oneline<br />";
	   }
	}
}

fclose($fh);

Mar 05, 09 - php,