Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Guesing gender based on name in PHP
# install gender http://www.php.net/manual/en/book.gender.php
sudo apt-get install libpcre3-dev
sudo pecl install gender
# generate data
mkdir ~/gender
sudo pear run-scripts pecl/gender
# eneble module
echo 'extension=gender.so' >> /etc/php5/cli/php.ini
<?php
use Gender\Gender;
$gender = new Gender();
printf("Wojciech is %s\n",
$gender->get('Wojciech', Gender::POLAND) == Gender::IS_MALE
? 'Male'
: 'Not male');
// prints Wojciech is Male
printf("Anna is %s\n",
$gender->get('Anna', Gender::POLAND) == Gender::IS_FEMALE
? 'Female'
: 'Not female');
// prints Anna is Female
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment