', '', ' 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 "Zip Code Not Assigned"; echo 'That Zip Code is currently not assigned, please try another zipcode:
Enter Zip Code:
'; } else { //if a zipcode is found, then we need to find the place to start and a place to end $end spaces away //I'm looking for a better way to extract the city/state info from the variable $pgdata.. could anyone help?!? $start = strpos($pgdata, "
"); //get start position, based on the pattern of the beginning of the zip table $end = $finish - $start + 10; //get 200 characters ahead of the start position.. echo "$start .. $finish .. $end "; $ziptable = substr( $pgdata, $start, $end ); //get the substring of $pgdata starting at $start and ending at $end $ziptable = str_replace($badThings['from'], $badThings['to'], $ziptable); //good to go, show the results echo "Results for zip code: $zip

Zip Code Search Results:

"; echo "\n$ziptable\n"; echo ""; } //end of if exit; default: //what to do if $do isn't set ?> Zip Code Retrieval
Enter Zip Code: