PHP Classes

PHP USPS API Address Validation: Get the details of a given address using USPS API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-12-20 (10 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 137 All time: 9,252 This week: 47Up
Version License PHP version Categories
usps-address-valid 3GNU General Publi...7.4E-Commerce, Web services, PHP 7
Description 

Author

This package is specific mainly for applications used in United States 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).

Picture of Jason Olson
  Performance   Level  
Name: Jason Olson is available for providing paid consulting. Contact Jason Olson .
Classes: 5 packages by
Country: United States United States
Age: ???
All time rank: 3195434 in United States United States
Week rank: 69 Up10 in United States United States Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

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


  Files folder image Files (6)  
File Role Description
Files folder imagedemo (1 file)
Files folder imagesrc (1 file)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (6)  /  demo  
File Role Description
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files (6)  /  src  
File Role Description
  Plain text file USPS.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadusps-address-valid-2023-12-20.zip 14KB
Downloadusps-address-valid-2023-12-20.tar.gz 13KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
cURL Download .zip .tar.gz Required for making API call Required
 Version Control Unique User Downloads Download Rankings  
 100%
Total:137
This week:0
All time:9,252
This week:47Up