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:

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(),
$input = new \Swagger\Client\Model\GetGenderRequest(); // \Swagger\Client\Model\GetGenderRequest | Gender request information
try {
$result = $apiInstance->nameGetGender($input);
} 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.

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