Click to See Complete Forum and Search --> : Please Critigue this code


msimonds
03-07-2008, 10:17 AM
Was wondering if someone could take a look at this code and let me know what they think?

This code uses a class that I found at phpclasses.org called ScoreScraper

What it is supposed to do is run and write out standard html to a file and then check to see if the file is over 24 hours old and if it is, delete it

Any critique is great, even if it is bad

Thanks,
Mike


<?php
$html_file = "nhl_scores.html";
$cache_reload_seconds = 86400;

if (file_exists($html_file))
{
if ((filemtime($html_file) + ($cache_reload_seconds - 90)) > time())
{
$test = write_to_html($html_file);
}
else
{
unlink($html_file);
}
}

function write_to_html($file)
{
include_once ('./score/class_ScoreScraper.php');
global $vbulletin,$output_score;
$ss = new ScoreScraper();
$league = 'nhl';


$ss->fetchScore($league);
foreach ($ss->scores as $score)
{
if ($score['isStarted'])
{
$output_score .= "<tr>\n\t<td class='alt1'><div class='smallfont'><strong>{$score['homeTeam']}</strong></div></td>\n\t<td align='right' class='alt1'><div class='smallfont' align='right'><strong>{$score['homeTeamScore']}</strong></div></td>\n</tr>\n";
$output_score .= "<tr>\n<td class='alt1'><div class='smallfont'><strong>{$score['awayTeam']}</strong></div></td>\n\t<td align='right' class='alt1'><div class='smallfont' align='right'><strong>{$score['awayTeamScore']}</strong></div></td>\n</tr>\n";
}
else
{
$output_score .= "<tr>\n\t<td class='alt1'><div class='smallfont'><strong>{$score['homeTeam']}</strong></div></td>\n\t<td align='right' class='alt1'><div class='smallfont' align='right'><strong>Game&nbsp;Time</strong></div></td>\n</tr>\n";
$output_score .= "<tr>\n\t<td class='alt1'><div class='smallfont'><strong>{$score['awayTeam']}</strong></div></td>\n\t<td align='right' class='alt1'><div class='smallfont' align='right'><strong>{$score['gameTime']}</strong></div></td>\n</tr>\n";
}
}
file_put_contents($file,$output_score,FILE_APPEND);
return $file;
}
?>