Quick and dirty, probably not the best way to do it.
$html_file="file.html";
$colors=array();
$fp=fopen($html_file,"r");
while(!feof($fp)) {
$tmp = fgets($fp);
if(preg_match("/bgcolor=\"(.*)\"/",$tmp,$matches)) {
array_push($colors,$matches[1]);
}
}
fclose($fp);
if($colors[count($colors)-1] == "#FF0000")
$bgcolor = "#000000";
else
$bgcolor = $colors[count($colors)-1];