Last active
September 12, 2022 17:04
-
-
Save sbarrat/be3376abda5cda1ff4e1 to your computer and use it in GitHub Desktop.
Detección de genero de Persona España
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
function generoPersona($nombre, $provider = 'genderAPI') | |
{ | |
$providers = array( | |
'genderAPI' => array( | |
'url' => 'https://gender-api.com/get?name=', | |
'pais' => '&country=ES' | |
), | |
'genderize' => array( | |
'url' => 'https://api.genderize.io/?name=', | |
'pais' => '&country_id=es' | |
) | |
); | |
if (array_key_exists($provider, $providers)) { | |
$dataProvider = $providers[$provider]; | |
} | |
$generoPersona = 'Hombre'; | |
$curl = curl_init($dataProvider['url'].$nombre.$dataProvider['pais']); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$result = json_decode(curl_exec($curl)); | |
if (is_a($result, 'stdClass') && property_exists($result, 'gender')) { | |
$generoPersona = ($result->gender == 'female')? 'Mujer' : 'Hombre'; | |
} | |
return $generoPersona; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment