Saturday, December 09, 2006

 

Scouring the NHL.com game sheets with your browser

PHP is a scripting language for HTML. Embed it in any web page (assuming that your server supports PHP, and they almost all do besides blogger) and it does what it does.

There is tonnes of free web space available out there, usually with advertising on it. You could even open a free acount somewhere, save the red bit of text as "joanette.php" or whatever name,
on the server, and run it from any computer using your web browser.

Below, in dark red, is a little PHP script that prints off the header of the NHL.com gamesheet for every Oilers game that Joanette reffed in during the 20052006 season. It can be easily changed to search for anything else in any other year that the NHL has game sheets on it's server, which is back to the 2000-2001 season I think.



$searchtext = "Joannette";
$team = "EDMONTON OILERS";
$season = "20052006";

function url_exists($url)
{
$handle = @fopen($url, "r");
if ($handle === false)
return false;
fclose($handle);
return true;
}

function headerstr($str)
{
$str= strstr($str, "
$ender = strpos($str, "
");

$str = substr($str, 0, $ender);
return $str;
}

for ($m = 1; $m <= 1230; $m++){
$url = "http://www.nhl.com/scores/htmlreports/".$season."/GS0".($m + 20000).".HTM";
if (url_exists($url) == true ){
$str = file_get_contents($url);
if ( strpos( $str, $searchtext ) > 0){
if (strpos( $str, $team ) > 0) {
$tmp = headerstr($str);
echo $tmp."

";

}
}
}
}

?>

If you go to an NHL.com gamesheet such as this one, and go to view - page source (CTRL + U with firefox) using your browser, it should become readily apparent that you can search for almost anything using this simple script.

So for example, if you wanted to search for every game that Rod Brind'Amour elbowed in, you would cut and paste that bit from a gamesheet and enter it as the $searchtext term as such:

$searchtext = "17
R. BRIND'AMOUR
2:00
Elbowing";

Just remember to enclose it in brackets and put the semicolon at the end.

It's really straightforward once you have a go.

PS. Blogger won't let me paste the snippet from the nhl.com game sheets without automatically modifying the HTML, but a text editor will.

Let me know if you have a go.

Comments:
Can someone tell me what SHOT(!) or SHOT(*) or HIT (!) or HIT(*) means in nhl stat play-by-plays?
 
This script does not work. I tired to copy and past, and all I got was junk :(

plz help
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?