if(!isset($_POST['search'])){ exit();} // Make sure user has hit "search"
$query = preg_replace("# #","+",$_POST['search']);
$total = 0;
for ($n=1;$n<10;$n++){ //For loop is for searching ALL Craigslist cities :)
echo '
';
$url = "http://www.craigslist.org/cgi-bin/search?".
"areaID=".$n.
"&subAreaID=0".
"&query=".$query.
"&catAbbreviation=sss".
"&minAsk=min".
"&maxAsk=max";
echo '$url = Link #'.$n.'';
$file = file_get_contents($url);
$total += AveragePrice($file);
}
$avg = $total / $n;
echo " THE TOTAL AVERAG IS: $".$avg."";
Function AveragePrice($file){
preg_match_all("#\$(.*)<#Us",$file,$prices);
$sum = 0;
$cnt = 1;
foreach ($prices as $price){
$sum += $price;
$cnt++;
}
$avg = $sum / $cnt;
echo 'The average for this City is: $'.$avg;
return $avg;
}
function EchoLinksTable ($file,$cols,$date){
preg_match_all("# Jul- $date(.*)a>#Uis",$file,$links);
$cnt = 0;
echo '
';
foreach ($links[0] as $link){
if ($cnt == 0){ echo '';}
$cnt++;
echo '| '.$link.' | ';
if ($cnt == $cols){
echo '
';
$cnt = 0;
}
}
echo '
';
}
?>