ZIPCodeWorld™ Utility PHP Component is a software development component which looks up the ZIPCodeWorld United States ZIP Code Database and PostalCodeWorld Canada Postal Code Database. It allows query by ZIP code, city name, alias city name, state code, phone area code, city type, county name, county FIPS, time zone, day light saving flag, latitude, longitude, etc.

ZIPCodeWorld™ is giving away free sample codes for the ZIPCodeWorld™ Utility PHP Component. You will need to run MySQL queries to fetch the data out of the database. We will demonstrate to you how to call and query 3 functions which are the Get function, Distance function and Radius function using the ZIPCodeWorld™ United States Gold Edition database in PHP.
First function is a normal data query for a particular ZIP Code. Second function is to query the distance between two given ZIP Codes. Last function is to query the data within a certain radius from the given ZIP Code.



/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: Include “zipcodeworld.class.php” to call all available functions ::*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

require('zipcodeworld.class.php');



/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: Create new object ::*/
/*:: ::*/
/*:: $zcw = new ZIPCodeWorld('', '', '', '', ::*/
/*:: ''); ::*/
/*:: ::*/
/*:: is database host name. ::*/
/*:: and are MySQL username and password. ::*/
/*::
is the name of table created and is the database name.::*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

$zcw = new ZIPCodeWorld('localhost', 'root', 'password', 'zipcodeworld', 'zipcodeworldus');


// If you have purchased a license key, please upload the “license.key” file to your server.
$zcw->licenseKey('/license.key');



/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: Function: get ::*/
/*:: array get (string $zip_code [,string $city] [,string $state_name]) ::*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

// Search by ZIP Code:

$result = $zcw->get('75303');

// Option Search by ZIP Code and City Name:
// $result = $zcw->get('75303', 'dallas');

// Option Search by ZIP Code, City Name and State Name:
// $result = $zcw->get('75303', 'dallas', 'texas');

echo 'ZIP Code: ' . $result[0]['ZIP_CODE'] . '
';
echo 'City: ' . $result[0]['CITY'] . '
';
echo 'State: ' . $result[0]['STATE'] . '
';
echo 'Area Code: ' . $result[0]['AREA_CODE'] . '
';
echo 'Alias City Name: ' . $result[0]['CITY_ALIAS_NAME'] . '
';
echo 'Abbreviation for Alias City Name: ' . $result[0]['CITY_ALIAS_ABBR'] . '
';
echo 'City Type: ' . $result[0]['CITY_TYPE'] . '
';
echo 'County Name: ' . $result[0]['COUNTY_NAME'] . '
';
echo 'County FIPS: ' . $result[0]['COUNTY_FIPS'] . '
';
echo 'Time Zone: ' . $result[0]['TIME_ZONE'] . '
';
echo 'Day Light Saving Flag: ' . $result[0]['DAY_LIGHT_SAVING'] . '
';
echo 'Latitude: ' . $result[0]['LATITUDE'] . '
';
echo 'Longitude: ' . $result[0]['LONGITUDE'] . '
';
echo 'County Elevation: ' . $result[0]['ELEVATION'] . '
';
echo 'Metropolitan Statiscal Area: ' . $result[0]['MSA2000'] . '
';
echo 'Primary Metropolitan Statiscal Area: ' . $result[0]['PMSA'] . '
';
echo 'Core Based Statiscal Area: ' . $result[0]['CBSA'] . '
';
echo 'Metropolitan Division: ' . $result[0]['CBSA_DIV'] . '
';
echo 'CBSA Title: ' . $result[0]['CBSA_TITLE'] . '
';
echo 'Persons Per Household: ' . $result[0]['PERSONS_PER_HOUSEHOLD'] . '
';
echo 'Population of the ZIP Code: ' . $result[0]['ZIPCODE_POPULATION'] . '
';
echo 'Counties Square Mileage: ' . $result[0]['COUNTIES_AREA'] . '
';
echo 'Households Per ZIP Code: ' . $result[0]['HOUSEHOLDS_PER_ZIPCODE'] . '
';
echo 'White Population: ' . $result[0]['WHITE_POPULATION'] . '
';
echo 'Black Population: ' . $result[0]['BLACK_POPULATION'] . '
';
echo 'Hispanic Population: ' . $result[0]['HISPANIC_POPULATION'] . '
';
echo 'Household Income: ' . $result[0]['INCOME_PER_HOUSEHOLD'] . '
';
echo 'House Value: ' . $result[0]['AVERAGE_HOUSE_VALUE'] . '
';



/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: Function: distance ::*/
/*:: double distance (string $zip_code1, $zip_code2 [,string $unit]) ::*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

echo $zcw->distance('00610', '75303') . ' Miles';
// Output:
// 2090.5834850135 Miles


echo $zcw->distance('00610', '75303', 'km') . ' KM';
// Output:
// 3364.4679881056 KM



/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: Function: radius ::*/
/*:: array radius (string $zip_code, $distance [,string $unit]) ::*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

$radius = $zcw->radius('00610', 10, 'miles');
// Output:
// show all ZIP Codes information around 00610 within 10 miles


foreach ($radius as $row){
echo 'ZIP Code: ' . $row['ZIP_CODE'] . '
';
echo 'City: ' . $row['CITY'] . '
';
echo 'State: ' . $row['STATE'] . '
';
echo 'Alias City Name: ' . $row['CITY_ALIAS_NAME'] . '
';
echo '
';
}


?>

www.zipcodeworld.com


Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/VNgVYubnrhw/10963