= 0 ) { if( preg_match( "/\/i", $iLine ) ) $found = 1; if( ($found == 1 ) && ( preg_match( "/\/i", $iLine ) ) ) $found = 2; if( ( $found == 2 ) && ( preg_match( "/\/i", $iLine ) ) ) $found = 0; if( $found == 2 ) { $iLine = preg_replace( "/\<[^\>]+>/", "", $iLine ); if( preg_match( "/^ [^ ]/", $iLine ) ) { $iLine = preg_replace( "/^ +/", "", $iLine ); $l ++; $ln[$l] = $iLine; $result .= $iLine; } else if($l > 2) $found = -1; } } } fclose( $fp ); } } while( ($result == "" ) && ( preg_match( "/Error opening USPS AMS API/i", $allResult) ) ); if( $result != "" ) { // Fix $ln[1] to remove

//$ln[1] = substr( $ln[1], 9 ); if( $l == 0 ) return FALSE; if( $l == 3 ) { $address = $ln[2]; $csz = $ln[3]; } else { $address = $ln[1]; $csz = $ln[2]; } preg_match( "/^(.+) ([A-Z]{2}) ([0-9]{5})-([0-9]{4})$/", $csz, $reg ); // Remove added STE... preg_replace( "/ Ste .+/", "", $address ); preg_replace( "/ Apt .+/", "", $address ); $city = $reg[1]; $state = $reg[2]; $zip = $reg[3] . "-" . $reg[4]; $address = rtrim( ucwords( strtolower( $address ) ) ); $city = rtrim( ucwords( strtolower( $city ) ) ); $address = preg_replace( "/Po /", "PO ", $address ); $address = preg_replace( "/Mck/", "McK", $address ); return TRUE; } return FALSE; } // Open Charter Org File $iFile = fopen( $iFileName, "rt" ) or die( "Cannot Open Input File" ); // Initalize variables $found = FALSE; // Loop Through all records while( ! feof( $iFile ) ) { $iLine = trim( fgets( $iFile, 2048 ) ); // Determine what District we are in if( preg_match( "/^ *District /", $iLine ) ) list(,,$district) = preg_split( "/\\\\/", $iLine ); // Look for ---- if( preg_match( "/^------/", $iLine ) ) { $found = TRUE; $lCnt = 0; continue; } // Look for FF if( preg_match( "/\f/", $iLine ) ) { $found = FALSE; continue; } // If in the address block if( $found ) { if( strlen( $iLine ) < 2 ){ $lCnt = 0; continue; } if( $lCnt == 0 ) unset( $add ); $lCnt ++; if( ( $lCnt > 2 ) && ( ! preg_match( "/, [A-Z]{2} /", $iLine ) ) ) { $lCnt --; $add[$lCnt] .= " "; } $add[$lCnt] .= trim(substr( $iLine, 0, 40 ) ); if( $lCnt == 1 ) $unit = trim( substr( $iLine, 44, 20 ) ); if( $lCnt == 3 ) { $co = sprintf( "%s|%s|%s|%s", $district, $add[1], $add[2], $add[3] ); $u[$co] .= $unit . " "; } } } fclose( $iFile ); $oFile = fopen( "CHARTER.OUT", "wt" ); ksort( $u ); reset( $u ); $oDistrict = ""; // Display all found Units foreach( $u as $key => $units ) { list($district,$name,$address,$csz) = preg_split( "/\|/", $key ); list($city, $sz) = preg_split( "/, /", $csz ); $state = substr( $sz, 0, 2); $zip = substr( $sz, 3 ); if( $district != $oDistrict ) { $oString = sprintf( "\n\n----- %s -----\n\n", $district ); echo $oString; fwrite( $oFile, $oString ); $oDistrict = $district; } $N = $name; $A = $address ; $C = $city; $S = $state; $Z = $zip; $ret = verifyAddress( &$name, &$address, &$city, &$state, &$zip ); if( $A == $address ) $address = ""; if( $C == $city ) $city = ""; if( $S == $state ) $state = ""; if( $Z == substr( $zip, 0, strlen( $Z ) ) ) $zip = ""; $CSZ = $C . ", " . $S . " " . $Z; $csz = $city . ", " . $state . " " . $zip; if( ! $ret ) $oString = "***"; else $oString = " "; $oString .= sprintf( "%-40.40s - %s\n %-40.40s - %s\n %-40.40s - %s\n\n", $N, $units, $A, $address, $CSZ, $csz ); fwrite( $oFile, $oString ); echo $oString; } ?>