I just upgraded Apache, PHP 4 and MYSQL 5, to the latest versions. Now I can't get the script to run on Win2003.
http://www.keithlucyk.com/NHL.php
<?php
$url = "http://www.nhl.com/standings/20052006/conference_standings.html"; // Trailing slash when not using filename
$file = "includes/cache/NHL_cache.html"; // file to write to. remember to chmod 777 to not get errors
$unique_start = '<!-- end showByWest -->'; // Where to begin to grab
$unique_end = '<!-- end showByConference -->'; // Where to end the grab
$cache_tolerance = 21600; // How many seconds old the cache file can get Set at 6 hours
//$cache_tolerance = 1; // How many seconds old the cache file can get Set at 1 second
//-----------------------------------------------------------
function update_content_NHL(&$NHLPrint) { // use this to modify the HTML tags etc
$NHLPrint = str_replace('bgcolor="#333366"', 'bgcolor="#d8d8c4"', $NHLPrint);
$NHLPrint = str_replace('<td colspan="13" height="1">', '<td colspan="13" height="1" bgcolor="#000000">', $NHLPrint);
$NHLPrint = str_replace('width="100%"', 'width="450"', $NHLPrint);
$NHLPrint = str_replace('cellpadding="2"', 'cellpadding="0"', $NHLPrint);
$NHLPrint = str_replace(' bgcolor="#ffffff"', '', $NHLPrint);
$NHLPrint = str_replace('class="HEADLINEGRAPH"', '', $NHLPrint);
$NHLPrint = str_replace('width="98%"', 'width="450"', $NHLPrint);
$NHLPrint = str_replace('bgcolor="#E1D8B9"', 'bgcolor="#eceadf"', $NHLPrint);
$NHLPrint = str_replace('bgcolor="#AFB088"', 'bgcolor="#eceadf"', $NHLPrint);
$NHLPrint = str_replace('<tr bgcolor="#FFFFFF"><td colspan="12"><br></td>', '</table ><br><table width="450" cellpadding="0" cellspacing="0" border="0">', $NHLPrint);
// use any replacement routines in here.
}
//-----------------------------------------------------------
function write_cache_NHL($filename) { // outputs the cached file
// echo 'writing from cache<br>';
$NHLPrint = implode("",@file( $filename ) );
update_content_NHL ($NHLPrint);
echo $NHLPrint;
}
//-----------------------------------------------------------
function check_domain_NHL($target) { // tests if domain is accessible by opening a socket to it
$fetch_domain = parse_url($target);
$fetch_domain = $fetch_domain[host];
$socket_handle = fsockopen("$fetch_domain", 80, $error_nr, $error_txt,30);
if(!$socket_handle)
{
echo $target . ' could not be reached.<br>';
return "false";
}
return "true";
} // function check_domain_NHL
//-------------------------------------------------------------
function update_cache_NHL($url,$unique_start,$unique_end,$file) {
// echo 'updating cache<br>';
if (check_domain_NHL($url)=='true') { // only update if we find the domain
$handle = fopen ("$url", "rb");
$fd = "";
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
$fd .= $data;
} while(true);
fclose ($handle);
if ($fd)
{
$start= strpos($fd, "$unique_start");
$start = $start + 0;
#echo "start found at " . $start . "<br>";
$finish= strpos($fd, "$unique_end");
#echo "finish found at " . $finish . "<br>";
$length= $finish - $start - 0;
$code=Substr($fd, $start, $length);
$code = strip_tags($code, '<b><tr><td><table><a>');
$code= $code."<CENTER>Updated: " . date ("F dS Y h:i A") . "</CENTER>";
}
// output to cache file
$tmpfile = fopen($file,"w+");
$fp = fwrite($tmpfile,$code);
fclose($tmpfile);
flush ();
}
}
//--------------Main section starts here-------------------------------
ini_set('max_execution_time', '0');
flush ();
// check how old the cache file is
if (file_exists($file)) {
clearstatcache(); // filemtime info gets cached so we must ensure that the cache is empty
$time_difference = time() - filemtime($file);
} else {
$time_difference = $cache_tolerance; // force update
}
if ($time_difference >= $cache_tolerance){ // update the cache if need be
update_cache_NHL($url,$unique_start,$unique_end,$file);
}
write_cache_NHL($file); // we always only output from cache
?>