PHP code example of markrogoyski / numverify-api-client-php
1. Go to this page and download the library: Download markrogoyski/numverify-api-client-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
markrogoyski / numverify-api-client-php example snippets
$accessKey = 'AccountAccessKeyGoesHere';
$api = new \Numverify\Api($accessKey);
$phoneNumber = '14158586273';
$validatedPhoneNumber = $api->validatePhoneNumber($phoneNumber);
// Phone number information
if ($validatedPhoneNumber->isValid()) {
$number = $validatedPhoneNumber->getNumber(); // 14158586273
$localFormat = $validatedPhoneNumber->getLocalFormat(); // 4158586273
$internationalPrefix = $validatedPhoneNumber->getInternationalFormat(); // +14158586273
$countryPrefix = $validatedPhoneNumber->getCountryPrefix(); // +1
$countryCode = $validatedPhoneNumber->getCountryCode(); // US
$countryName = $validatedPhoneNumber->getCountryName(); // United States of America
$location = $validatedPhoneNumber->getLocation(); // Novato
$carrier = $validatedPhoneNumber->getCarrier(); // AT&T Mobility LLC
$lineType = $validatedPhoneNumber->getLineType(); // mobile
}
// Use optional country code parameter for local (non-E.164) phone numbers
$phoneNumber = '4158586273';
$countryCode = 'US';
$validatedPhoneNumber = $api->validatePhoneNumber($phoneNumber, $countryCode);
// PHP Interfaces
$stringRepresentation = (string) $validatedPhoneNumber;
$jsonRepresentation = json_encode($validatedPhoneNumber);
$countries = $api->getCountries();
// Find countries (by country code or by name)
$unitedStates = $countries->findByCountryCode('US');
$japan = $countries->findByCountryName('Japan');
// Country information
$usCountryCode = $unitedStates->getCountryCode(); // US
$usCountryName = $unitedStates->getCountryName(); // United States
$usDialingCode = $unitedStates->getDialingCode(); // +1
$japanCountryCode = $japan->getCountryCode(); // JP
$japanCountryName = $japan->getCountryName(); // Japan
$japanDialingCode = $japan->getDialingCode(); // +81
// Country collection is iterable
foreach ($countries as $country) {
$countryCode = $country->getCountryCode();
$countryName = $country->getCountryName();
$dialingCode = $country->getDialingCode();
}
// Country collection PHP interfaces
$numberOfCountries = count($countries);
$jsonRepresentation = json_encode($numberOfCountries);
// Country PHP interfaces
$stringRepresentation = (string) $unitedStates; // US: United States (+1)
$jsonRepresentation = json_encode($unitedStates);
// Construct API to use HTTPS for API calls
$useHttps = true;
$api = new \Numverify\Api($accessKey, $useHttps); // Optional second parameter
// Numverify API server error
try {
$validatedPhoneNumber = $api->validatePhoneNumber($phoneNumber);
} catch (\Numverify\Exception\NumverifyApiFailureException $e) {
$statusCode = $e->getStatusCode(); // 500
$message = $e->getMessage(); // Unknown error - 500 Internal Server Error
}
// Numverify API failure response
try {
$validatedPhoneNumber = $api->validatePhoneNumber($phoneNumber);
} catch (\Numverify\Exception\NumverifyApiFailureException $e) {
$statusCode = $e->getStatusCode(); // 200
$message = $e->getMessage(); // Type:invalid_access_key Code:101 Info:You have not supplied a valid API Access Key.
}