<?php

// 25 August 2009
// http://www.nyc.com/search/find.aspx?secid=24&name=parking&sort=editor&dir=desc&bdcid=21032000&pagefrom=21


$count = 0;
echo "ID,Name,Phone,Address,City,State,Zip\n";

for ($page = 1; $page < 1490; $page += 20)
{
	$url = "http://www.nyc.com/search/find.aspx?secid=24&name=parking&sort=editor&" .
		"dir=desc&bdcid=21032000&pagefrom=" . $page;

	$html = file_get_contents($url);
	$x = strpos($html, "<a class=\"rn\"");
	while ($x > 0)
	{
		$end = strpos($html, "<a class=\"rn\"", $x + 1);
		if ($end <= 0)
			$end = strlen($html);
		$garage = substr($html, $x, $end - $x);

		$y = strpos($garage, ">");
		$end = strpos($garage, "</a>", $y);
		$name = trim(substr($garage, $y + 1, $end - $y - 1));

		$y = strpos($garage, "<br />", $y);
		$y = strpos($garage, "<br />", $y + 1);
		$end = strpos($garage, "<br />", $y + 1);
		$location = trim(substr($garage, $y + 6, $end - $y - 6));
		
		$y = strpos($garage, "<b>", $y + 1);
		$end = strpos($garage, "</b>", $y);
		$phone = trim(substr($garage, $y + 3, $end - $y - 3));

		++$count;
		echo "$count,\"$name\",\"$phone\"";
		$elements = explode(",", $location);
		foreach ($elements as $element)
			echo ",\"" . trim($element) . "\"";
		echo "\n";

		$x = strpos($html, "<a class=\"rn\"", $x + 1);
	}
}
?>
