/*************************************************************************************
* zip.php *
* This script uses the free zipcode search engine at: zipinfo.com *
* to retrieve the name of the town and state that the zipcode is *
* related to. *
* Currently in use for an application in which people can search *
* through a database by zipcode... it's a nice little bonus to be able *
* to return recognizable information (city,state) to the user *
* allow_url_fopen must be set to 1 (on) in php.ini for this to work *
* *
**************************************************************************************/
$badThings['from'] = array('
', '', ' align=center', '><');
$badThings['to'] = array(' ', '', '', ">\n<");
function getpgdata($zip) { //Function to retrieve the contents of a webpage and put it into $pgdata
$pgdata =""; //initialize $pgdata
$fd = fopen("http://www.zipinfo.com/cgi-local/zipsrch.exe?cnty=cnty&ac=ac&tz=tz&ll=ll&msa=msa&Go=Go&zip=$zip","r");
//open the url based on the user input and put the data into $fd
while(!feof($fd)) //while loop to keep reading data into $pgdata till its all gone
{
$pgdata .= fread($fd, 1024); //read 1024 bytes at a time
}
fclose($fd); //close the connection
return $pgdata; //return the entire page data in $pgdata
}
switch ($_GET['do']) {
case "retrieve":
//this is what we do if $do is set to retrieve
echo getpgdata($_REQUEST['zip']); //Use getpgdata function to read the specified zip code information
$pgdata = getpgdata($_REQUEST['zip']); //Use getpgdata function to read the specified zip code information
if (preg_match("/is not currently assigned/", $pgdata)) { //display an error if the zip code is not found
echo "