Skip to content

Instantly share code, notes, and snippets.

@wowo
Last active May 5, 2021 23:01
Show Gist options
  • Save wowo/6154154 to your computer and use it in GitHub Desktop.
Save wowo/6154154 to your computer and use it in GitHub Desktop.
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