bpat1434
came up with this for me.
Thank you again!
Now I need to insert all this into my database.
What would be the best and easiest format as to be able to then retrieve info and insert into my own table?
1 table (standings)
12 Fields (rank, rankdelta,driver,points etc) ?
but will mark this one resolved and stay in coding section.
<?php
$url = 'http://sports.yahoo.com/nascar/standings';
$html = file_get_contents($url);
// First, get that one single table.
preg_match('~(<table width="100%" border="0" cellspacing="0" cellpadding="0">.*<tr.*class="ysptblthbody1".*>.*</table>)~iUs', $html, $matches);
// $matches[0] is now the full match (e.g. the whole $html content)
// $matches[1] is just the table we need
// We'll split it up between those in the contention and those not
preg_match('~(<tr class="ysprow(?:1|2)">.*)<tr><td.*><img.*></td></tr>(<tr class="ysprow(?:1|2)".*>.*</tr>.*)</table>~iUs', $matches[1], $parts);
// $parts[1] are those in contention
// $parts[2] are the other drivers in the field
// Look for all the information for those in contention, save to $matches
preg_match_all('~<tr class="ysprow.*">.*<td.*>.*([\d]*)</td>.*<td.*>([+|-][\d]*)</td><td class=".*padded2px.*".*>.*<a.*>(.*)</a></td>.*<td class=".*ysptblclbg6.*".*>(.*)</td>.*<td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td>.*</tr>~iUs', $parts[1], $matches, PREG_SET_ORDER);
// Look for all the information for the other drivers, store in $matches2
preg_match_all('~<tr class="ysprow.*">.*<td.*>.*([\d]*)</td>.*<td.*>([+|-][\d]*)</td><td class=".*padded2px.*".*>.*<a.*>(.*)</a></td>.*<td class=".*ysptblclbg6.*".*>(.*)</td>.*<td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td><td.*>(.*)</td>.*</tr>~iUs', $parts[2], $matches2, PREG_SET_ORDER);
// Prepare our array for population
$drivers = array(
'contention' => array(),
'field' => array()
);
// Add the drivers in contention
foreach($matches as $match)
{
$drivers['contention'][$match[1]] = array(
'rank' => $match[1],
'rank_delta' => $match[2],
'driver' => $match[3],
'points' => $match[4],
'behind' => $match[5],
'start' => $match[6],
'poles' => $match[7],
'wins' => $match[8],
'top5' => $match[9],
'top10' => $match[10],
'dnf' => $match[11],
'winnings' => $match[12]
);
}
// Add those drivers that are in the rest of the field
foreach($matches2 as $match)
{
$drivers['field'][$match[1]] = array(
'rank' => $match[1],
'rank_delta' => $match[2],
'driver' => $match[3],
'points' => $match[4],
'behind' => $match[5],
'start' => $match[6],
'poles' => $match[7],
'wins' => $match[8],
'top5' => $match[9],
'top10' => $match[10],
'dnf' => $match[11],
'winnings' => $match[12]
);
}
echo '<pre>'.print_r($drivers, 1).'</pre>';