Clarification of Answer by
runix-ga
on
23 Jun 2002 16:12 PDT
Hey :) Im happy you liked the script!
I've commented it a bit, please askme if you don't understand
something.
Here's the new version, now it reads the Missed cut table.
Good luck!
----------------------
<?php
$page_array= file("http://www.lpga.com/statistics/leaderboard.cfm");
# $page_array= file("leaderboard.cfm");
$players=$missed_cut=array();
$started=0;
$missed=0;
foreach ($page_array as $page) {
if (!$missed){
if (eregi('MISSED CUT',$page)){
$missed=1;
$started=0;
$data=array();
continue;
}
# new record starts...
if (ereg('<tr bgcolor="EEEEEE">|</table>',$page)){
if (count($data)){
$players[$player_name]=$data;
}
$player_name='';
$data=array();
$started=1;
}
# 'start' and 'current'
if (empty($player_name) && $started && preg_match("|<td
align=center><font face=\"Verdana,Arial,Helvetica,sans serif\"
size=2>(.*?)</font>|i",$page,$out)){
if (!isset($data['start'])){$data['start']=$out[1]; }
elseif (!isset($data['curr'])){$data['curr']=$out[1]; }
}
# player name
if (eregi("([\t]+)<td align=([a-z]+)><font
face=\"Verdana,Arial,Helvetica,sans serif\" size=2><a
href=\"/players/playerpage.cfm\?player_id=([0-9]+)\">",$page)) {
preg_match_all ("|.cfm\?player_id=([0-9]+)\">(.*?)</a>|", $page,
$out, PREG_PATTERN_ORDER);
$player_name = $out[2][0];
}
# date (it differs from the other fields 'thru', 'to_par', etc
because the line doesn't ends with </font> (they close the tag on the
next line)
if (!empty($player_name) && !isset($data['today'])){
preg_match('/<td align=center><font
face="Verdana,Arial,Helvetica,sans serif" size=2>([0-9]+:[0-9]+
[AP]M|E|[\+-][0-9])/i',$page,$out);
$data['today']=$out[1];
}
# thru, to_par, r1, r2, r3, etc
elseif (!empty($player_name) and eregi("<td align=center><font
face=\"Verdana,Arial,Helvetica,sans serif\" size=2>",$page)) {
preg_match_all ("|<td align=center><font
face=\"Verdana,Arial,Helvetica,sans serif\"
size=2>(.*?)</font></td>|", $page, $out, PREG_PATTERN_ORDER);
$fields=array('thru','to_par','1','2','3','4','total');
foreach($fields as $field){
if (!isset($data[$field])){
$data[$field]=$out[1][0]." ";
break;
}
}
}
}else{
if (ereg('<tr bgcolor="EEEEEE">|</table>',$page)){
# print "new player, closing: '$player_name'\n";
if (count($data)){
$missed_cut[$player_name]=$data;
}
$player_name='';
$data=array();
$started=1;
continue;
}
if ($started and preg_match('|<td align=left><a
href="/players/playerpage.cfm\?player_id=[0-9]+"><font
face="Verdana,Arial,Helvetica,sans serif"
size=2>(.*?)</font></a></td>|i',$page,$out)){
$player_name=$out[1];
continue;
}
if ($started and $player_name and preg_match('|<td
align=center><font face="Verdana,Arial,Helvetica,sans serif"
size=2>(.*?)</font>( )?</td>|i',$page,$out)){
foreach(array('r1','r2','total') as $k){
if (!isset($data[$k])){
$data[$k]=$out[1];
break;
}
}
continue;
}
}
}
$aussies = array("Karrie Webb", "Rachel Teske", "Jane Crafter");
echo "<table border=\"1\">";
echo "<tr><td colspan=11>LPGA Tour Scoreboard</td></tr>";
echo "<tr> <td>Player Name</td> <td>Current</td> <td>Today</td>
<td>Total Score</td> <td>Start</td> <td>Today</td> <td>Thru</td>
<td>R1</td> <td>R2</td> <td>R3</td> <td>R4</td> </tr>";
foreach ($players as $name => $data) {
if (in_array($name,$aussies)) {
echo "<tr>";
echo "<td>$name</td>";
foreach (array('curr','today','total', 'start', 'today',
'thru','1','2','3','4') as $null=>$k) {
if ($k!='null'){
echo "<td>$k : ".$data[$k]."</td>";
}
}
echo "</tr>\n";
}
}
echo "</table>";
print "Missed cut:\n";
foreach($missed_cut as $k=>$p){
print "$k:\n";
foreach($p as $k=>$v){
print "\t$k: $v\n";
}
print "<br />\n";
}
?>