Skip to content

Instantly share code, notes, and snippets.

Last active May 5, 2021 23:01
What would you like to do?
Guesing gender based on name in PHP
# install gender
sudo apt-get install libpcre3-dev
sudo pecl install gender
# generate data
mkdir ~/gender
sudo pear run-scripts pecl/gender
# eneble module
echo '' >> /etc/php5/cli/php.ini
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