ACJavascript
02-11-2006, 02:20 AM
Hey all,
Okay, I have a personal NASCAR league in the works, and I am sick of updating the records myself. So, I wanted to pull the content from this page:
http://www.nascar.com/races/cup/2005/data/standings_official.html
and read the standings then update my own table.
So far I've got:
$myfile=file_get_contents("http://www.nascar.com/races/cup/2005/data/standings_official.html");
Now my question is - Should I use preg_match_all to scan through the TD's?
or is there a better method?
Any ANY help is greatly appreciated! :)
chump2877
02-11-2006, 05:34 AM
I was bored so here you go, you can format the table however you like....let me know if you have questions:
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<?
$myfile = file_get_contents("http://www.nascar.com/races/cup/2005/data/standings_official.html");
$start = strpos($myfile, "Winnings");
$finish = strpos($myfile, "* Denotes Rookie");
$length = $finish - $start;
$string = substr($myfile,$start,$length);
$string = str_replace('>','>~',$string);
$string = str_replace('</tr>','</tr>^',$string);
$string = strip_tags($string);
$string = substr($string,10);
trim($string);
$lines = explode("^",$string);
print "<table cellpadding=5>";
foreach ($lines as $key => $val)
{
if (strlen($val) < 30)
{
unset($lines[$key]);
continue;
}
$data = explode("~",$lines[$key]);
print "<tr>";
foreach ($data as $key => $val)
{
if ($val == "" || $val =="*")
{
unset($data[$key]);
continue;
}
print "<td>" . $val . "</td>";
}
print "</tr>";
}
print "</table>";
?>
</BODY>
</HTML>
ACJavascript
02-11-2006, 07:18 PM
Hey chump2877, THANK YOU SO MUCH! Sweet! :D
chump2877
02-11-2006, 10:31 PM
you're welcome :thumbsup:
hopefully you understand how the code works...you don;t need to use regular expressions for what you want to do....
ACJavascript
02-11-2006, 10:34 PM
Yes, I do understand the code, you have open my eyes :D
This is great! thanks!
Element
02-12-2006, 09:33 PM
Though, regular expressions would shorten the code probably by 3/4 and speed up the script.
ACJavascript
02-13-2006, 04:05 AM
Hey Element,
Right now speed isnt' an issue, but for future reference, do you have some code?? Would like to see hwo its done.
chump2877
02-13-2006, 04:28 AM
regex gives me headaches, that's why i didn't use it....:D
ACJavascript
02-13-2006, 06:25 AM
Me two man, but good to learn hehe :D