Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2023-12-20 (9 months ago) | | Not yet rated by the users | | Total: 137 | | All time: 9,252 This week: 47 |
|
Description | | Author |
This package is specific mainly for applications used in United States .
This class can get the details of a given address using USPS API.
It can send an HTTP request to the USPS API Web server to get the details of a given United States address.
The class returns an array with the street address, city, state, and the five-digit postal code.
This package is updated to support the latest USPS API v3 (as of 2023). | |
|
|
Innovation award
Nominee: 2x |
|
Example
<?php
/**
* Copyright (c) 2019. ReddingWebPro / Jason J. Olson, This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 3
* of the License.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. You should have received a copy of the GNU General Public License along with this program. If not,
* see <https://www.gnu.org/licenses/>.
*/
/**
* Created by ReddingWebPro/ReddingWebDev
* User: Jason J. Olson
* License: GNU GPLv3
* GitHub: https://github.com/reddingwebpro/usps_address_validation
* Version 2.0
* Date: 3/6/2019 (rev. 9/19/23)
*
*/
// example code shown below:
require('USPS.php');
use RedWebDev\src\USPS;
$uspsZip = new USPS('Consumer Key','Consumer Secret'); // insert your api key from USPS
$address = '1600 Amphitheatre Parkway'; // address line is required
$city = 'Mountain View';
$state = 'CA'; //looking for the two character state
$return = $uspsZip->getNormalized($address, $city, $state);
echo "<ul>";
echo "<li>Address: " . $return['address']['streetAddress'];
echo "<li>Address 2: " . $return['address']['secondaryAddress'];
echo "<li>City: " . $return['address']['city'];
echo "<li>State: " . $return['address']['state'];
echo "<li>Zip: " . $return['address']['ZIPCode'];
|
Details
usps_address_validation
This CLASS is designed to take advantage of the USPS API for looking up the corrected (normalized) address for a given physical address. There is very little examples of implementing the USPS API in PHP.
Configuration
When you instantiate the class, include the API key. See the example.php file for usage. If you don't have a valid USPS.com API, you can get one free at https://www.usps.com/business/web-tools-apis/welcome.htm
Revision History:
-
1.0 Initial Release
-
1.1 Bugfix 500 error.
-
2.0 Updated for new USPS API V3 & PHP 8 coding standards
This code was written by request by another developer on phpClasses.org because Streetlayers is going away very soon.
License
GNU General Public License v3.0 (GNU GPLv3)
http://www.gnu.org/licenses/gpl-3.0-standalone.html
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.