Last active
May 5, 2021 23:01
-
-
Save wowo/6154154 to your computer and use it in GitHub Desktop.
Guesing gender based on name in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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