Last active
December 16, 2015 00:18
-
-
Save dlion/5346277 to your computer and use it in GitHub Desktop.
Function to extract birthdate and sex from fiscal code.
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 | |
function trova_data_fiscale($codice) | |
{ | |
$mesi = array('A' => '01', 'B' => '02', 'C' => '03', 'D' => '04', 'E' => '05', 'H' => '06', 'L' => '07', 'M' => '08', 'P' => '09', 'R' => '10', 'S' => '11', 'T' => '12'); | |
$dati_finali = array(); | |
$data_presa = substr(strtoupper($codice),6,5); | |
$anno = substr($data_presa,0,2); | |
$mese = substr($data_presa,2,1); | |
$giorno = strval(substr($data_presa,3,2)); | |
if($giorno >= 40) | |
{ | |
$sesso = "F"; | |
$giorno -= 40; | |
} | |
else | |
$sesso = "M"; | |
$dati_finali[0] = strval($giorno)."/".$mesi[$mese]."/19".$anno; | |
$dati_finali[1] = $sesso; | |
return $dati_finali; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment