rideside.net

home | archive | comics | about

reply to the comment you are replying too
Posted by tgl on 2005-06-15 16:15:48 +0000

standings

<!--break-->

<?php
$url = 'http://sports.yahoo.com/mlb/standings';
$response = file_get_contents($url);

$r = preg_split('/\n/', $response);

$output = '<h3>It looks like...</h3>';

$pattern1 = '/Regular Standings/';
$pattern2 = '/ysptblthbody1/';
$pattern3 = '/\"\/mlb\/teams\/(.*)\"/';

$ii = 0;
$jj = 0;
$kk = 0;

for ($ii = 0; $ii < count($r); $ii++) {
$line = $r$ii];

// Regular Standings
if (preg_match($pattern1, $line, $match)) {
$ii++;

for ($jj = $ii; $jj < count($r); $jj++) {
$line = $r$jj];

// table top
if (preg_match($pattern2, $line, $match)) {
$jj++;
$output .= '<p><table width=200>';
$output .='<tr>';
$output .='<td width=100>';
$output .='<td width=20>W';
$output .='<td width=20>L';
$output .='<td width=30>Pct';
$output .='<td width=30>GB';
$output .='</tr>';

for ($kk = $jj; $kk < count($r); $kk++) {
$line = $r$kk];

if (preg_match($pattern2, $line, $match)) {
break;
} else if (preg_match($pattern3, $line, $match)) {
if (preg_match('/([A-Z][A-Z]?[a-z]*\s?)+/', $line, $match)) {
$name = $match[0];
}

$output .= '<tr>';
$output .= '<td>'. $name . '</td>';
$output .= $r$kk + 1];
$output .= $r$kk + 2];
$output .= $r$kk + 3];
$output .= $r$kk + 4];
$output .= '</tr>';
}

}// for kk

$output .= '</p></table>';
}// pattern2
}// for jj

}// pattern1
}// for ii

print $output;

?>

Find me on github.