Here is the code that does the bull work, note that it is tied heavily to the html input so if they change their site layout it may need to be reworked
<?php
$url = "http://ci.baton-rouge.la.us/reports/public/cdactiv.html";
$page = GetHTML($url,$a,true);
//find the start of the preformated text
$trim_to = strpos($page['html'],'<pre>');
//find the end of the line that begins the preformated text
$trim_to = strpos($page['html'],"\n",$trim_to);
//find the start of the city name
while(!eregi('[a-z]',substr($page['html'],$trim_to,1))) {$trim_to++;}
//find the end of the city name
$stop_at = strpos(strtolower($page['html']),' area',$trim_to);
//calculate the length of the city name
$length = $stop_at - $trim_to;
//pull out the name of the city
$city = substr($page['html'],$trim_to,$length);
$stop = strpos($page['html'],"\n",$trim_to)-$trim_to;
//find the first line containing traffic accident data
while(!eregi('^[0-9]{2}:[0-9]{2}',substr($page['html'],$trim_to,$stop))) {
$trim_to += $stop;
$stop = strpos($page['html'],"\n",$trim_to) - $trim_to + strlen("\n");
}
//find the end of the traffic accident data
$stop = strpos($page['html'],'</style>',$trim_to);
$length = $stop - $trim_to;
//create a string of just the accidents
$text = substr($page['html'],$trim_to,$length);
$text = htmlentities($text);
//turn the acidents into an array
$text = explode("\n",$text);
//capitalize city properly
$city = explode(" ",$city);
$fmt_city = '';
foreach($city as $part) {$fmt_city .= ucfirst(strtolower($part));}
echo $city . " had " . count($text) . " accidents recently.<br /><br />";
foreach($text as $accident) {echo $accident . "<br />";}
?>
and for completness here is the code for GetHTML
<?php
function GetHTML ($url, &$delta, $cut = false, $complete = true) {
$url_stuff = parse_url($url);
if(empty($url_stuff['host'])) {return FALSE;}
if(empty($url_stuff['path'])) {$url_stuff['path'] = '/';}
if(empty($url_stuff['query'])) {$url_stuff['query'] = '';}
else {$url_stuff['query'] = '?' . $url_stuff['query'];}
$fp = fsockopen ($url_stuff['host'], 80, $errno, $errstr, 30);
if (!$fp) {exit;}
else {
$header = "GET " . $url_stuff['path'] . "?" . $url_stuff['query'] ;
$header = $header . " HTTP/1.0\r\nHost: " . $url_stuff['host'] . "\r\n\r\n";
fputs ($fp, $header);
$header = '';
$body = '';
$act = false;
$end = false;
while (!feof($fp)) {
$line = fgets ($fp,1024);
if (!$act) {
if (strpos($line, "\r\n", 0) == 0) {
$header .= $line;
if (!$complete) $end = true;
$act = true;
} else {
$header .= $line;
} //end if
} else {
$body = $body . $line;
} //end if
} //end while
fclose ($fp);
} //end if
return array('headers'=>$header,'html'=>$body);
}
?>