How to get the gender of a first name in PHP
Here is a simple method to determine the gender of someone’s name. Begin by referencing our Validate API Client:
"require": {
"cloudmersive/cloudmersive_validate_api_client": "^1.4",
}
Call nameGetGender, as follows:
<?php
require_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');$apiInstance = new Swagger\Client\Api\NameApi(
new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\GetGenderRequest(); // \Swagger\Client\Model\GetGenderRequest | Gender request informationtry {
$result = $apiInstance->nameGetGender($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling NameApi->nameGetGender: ', $e->getMessage(), PHP_EOL;
}
?>
Now we input the desired name and country code (if possible, to narrow the results):
{
"FirstName": "Lydia",
"CountryCode": "US"
}
And it will return the following:
{
"Successful": true,
"Gender": "Female"
}
See? Very simple.