Detección de genero de Persona España
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