How to Parse and Validate a Full Name in PHP

Having the ability to parse entire names from within PHP can open up some nice possibilities. For one, it can be of great help when sending templated emails. We don’t need to dive into any name databases today, however. Instead we are going to use an API, which will save us a ton of work.

To begin, we need to install our client, which can be accomplished from the command line of Composer.

composer require cloudmersive/cloudmersive_validate_api_client

After installation has finished, we can now implement our function:

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\NameApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as GuzzleHttp\Client(),$config);$input = new \Swagger\Client\Model\FullNameValidationRequest(); // \Swagger\Client\Model\FullNameValidationRequest | Validation request informationtry {$result = $apiInstance->nameValidateFullName($input);print_r($result);} catch (Exception $e) {echo 'Exception when calling NameApi->nameValidateFullName: ', $e->getMessage(), PHP_EOL;}?>

All that’s left to do now is input a name to test it out. It’s just as easy as that.

Image for post

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