Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function GetConsonanti($stringa)
- {
- $retval = "";
- $ln = strlen($stringa);
- for ($i = 0; $i < $ln; $i++)
- {
- $ch = substr($stringa, $i, 1);
- if (($ch != "A") and ($ch != "E") and ($ch != "I") and ($ch != "O") and ($ch != "U"))
- {
- $retval = $retval . $ch;
- }
- }
- return $retval;
- }
- function GetVocali($stringa)
- {
- $retval = "";
- $ln = strlen($stringa);
- for ($i = 0; $i < $ln; $i++)
- {
- if ((substr($stringa,$i,1) == "A") or (substr($stringa,$i,1) == "E") or (substr($stringa,$i,1) == "I") or (substr($stringa,$i,1) == "O") or (substr($stringa,$i,1) == "U"))
- {
- $retval = $retval . substr($stringa,$i,1);
- }
- }
- return $retval;
- }
- function GetCarCognome($cognome)
- {
- $stcons = GetConsonanti($cognome);
- $stvoc = GetVocali($cognome);
- $ln = strlen($stcons);
- if (strlen($stcons) >= 3)
- {
- Return substr($stcons, 0, 3);
- }
- if (strlen($stcons) == 2)
- {
- if (strlen($stvoc) == 0)
- {
- Return $stcons . "X";
- }
- if (strlen($stvoc) > 0)
- {
- Return $stcons . substr($stvoc, 0, 1);
- }
- }
- if (strlen($stcons) == 1)
- {
- if (strlen($stvoc) == 0)
- {
- Return "";
- }
- if (strlen($stvoc) == 1)
- {
- Return $stcons . $stvoc . "X";
- }
- if (strlen($stvoc) > 1)
- {
- Return $stcons . substr($stvoc,0,2);
- }
- }
- }
- function GetCarNome($nome)
- {
- $stcons = GetConsonanti($nome);
- $stvoc = GetVocali($nome);
- if (strlen($stcons) >= 4)
- {
- Return substr($stcons, 0,1) . substr($stcons, 2,1) . substr($stcons,3,1);
- }
- if (strlen($stcons) == 3)
- {
- Return $stcons;
- }
- if (strlen($stcons) == 2)
- {
- if (strlen($stvoc) == 0)
- {
- Return $stcons . "X";
- }
- if (strlen($stvoc) >= 1)
- {
- Return $stcons . substr($stvoc,0,1);
- }
- }
- if (strlen($stcons) == 1)
- {
- if (strlen($stvoc) == 0)
- {
- Return "";
- }
- if (strlen($stvoc) == 1)
- {
- Return $stcons . $stvoc . "X";
- }
- if (strlen($stvoc) > 1)
- {
- Return $stcons . substr($stvoc,0,2);
- }
- }
- }
- function Calcola($par1,$par2,$par3, $par4, $par5)
- {
- $ValoriPari = array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25);
- $ValoriDispari = array (1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 0, 0, 0, 0, 0, 0, 0, 1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23);
- $basta = False;
- $nc = 0;
- $nv = 0;
- $par1 = str_replace("'", "", $par1);
- $par1 = str_replace(" ", "", $par1);
- $par1 = trim($par1);
- $par2 = str_replace("'", "", $par2);
- $par2 = str_replace(" ", "", $par2);
- $par2 = trim($par2);
- $par1 = strtoupper($par1);
- $par2 = strtoupper($par2);
- if (strlen($par1) <= 1)
- {
- Return "";
- }
- if (strlen($par2) <= 1)
- {
- Return "";
- }
- $letterecognome = GetCarCognome($par2);
- $letterenome = GetCarNome($par1);
- $rst = $letterecognome . $letterenome;
- $par3 = trim($par3);
- if(strtotime($par3))
- {
- $data = strtotime($par3);
- } else {
- Return "";
- }
- $anno = date("y", $data);
- $stanno = strval($anno);
- $stmese = date("m", $data);
- $mese = intval($stmese);
- $sesso = trim($par4);
- $sesso = strtoupper($sesso);
- if (($sesso == "F") or ($sesso == "M"))
- {
- } else {
- Return "";
- }
- $codice = trim($par5);
- $codice = $par5;
- if ($mese == 1)
- {
- $stmese = "A";
- }
- if ($mese == 2)
- {
- $stmese = "B";
- }
- if ($mese == 3)
- {
- $stmese = "C";
- }
- if ($mese == 4)
- {
- $stmese = "D";
- }
- if ($mese == 5)
- {
- $stmese = "E";
- }
- if ($mese == 6)
- {
- $stmese = "H";
- }
- if ($mese == 7)
- {
- $stmese = "L";
- }
- if ($mese == 8)
- {
- $stmese = "M";
- }
- if ($mese == 9)
- {
- $stmese = "P";
- }
- if ($mese == 10)
- {
- $stmese = "R";
- }
- if ($mese == 11)
- {
- $stmese = "S";
- }
- if ($mese == 12)
- {
- $stmese = "T";
- }
- $stgiorno = date("d", $data);
- $giorno = intval($stgiorno);
- If ($sesso == "F")
- {
- $giorno = $giorno + 40;
- }
- $stgiorno = strval($giorno);
- $rst = $rst . $stanno . $stmese . $stgiorno . $codice;
- $sommapari = 0;
- $sommadispari = 0;
- $sommatotale = 0;
- $c = 1;
- for ($i = 0; $i <= 14; $i++)
- {
- $intero = ord(strtoupper(substr($rst,$i,1))) - ord("0");
- if (($c % 2) == 0)
- {
- $sommatotale = $sommatotale + $ValoriPari[$intero];
- } else {
- $sommatotale = $sommatotale + $ValoriDispari[$intero];
- }
- $c = $c + 1;
- }
- $IntCodice = ($sommatotale % 26) + ord("A");
- $rst = $rst . chr($IntCodice);
- Return $rst;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement