How to Validate an Address in PHP

Do you collect and store user addresses for shipping and billing purposes? If the answer is yes, then you know the importance of ensuring that the gathered location information is accurate. The following API will allow you to validate street addresses, including all major international addresses, by parsing the input data request in PHP.

Image for post
Image for post

Our first step in the validation process is to install the SDK by running this command:

composer require cloudmersive/cloudmersive_validate_api_client

Next, we will input both our API key and our parse request (including street address, city, state/province, postal code, country name, and country code) and call the function with the following code:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

The finished result will verify the validity of the location; if the address is valid, longitude and latitude will be indicated as well.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store