Advertisement
metallaro1980

Codice Fiscale PHP

Dec 28th, 2020
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.46 KB | None | 0 0
  1. <?php
  2.  
  3.  function GetConsonanti($stringa)
  4.  {
  5.   $retval = "";
  6.   $ln = strlen($stringa);  
  7.   for ($i = 0; $i < $ln; $i++)
  8.   {
  9.       $ch = substr($stringa, $i, 1);
  10.       if (($ch != "A") and ($ch != "E") and  ($ch != "I") and ($ch != "O") and ($ch != "U"))      
  11.       {
  12.         $retval = $retval . $ch;
  13.       }
  14.   }
  15.  
  16.   return $retval;
  17.  }
  18.  
  19.  function GetVocali($stringa)
  20.  {
  21.   $retval = "";
  22.   $ln = strlen($stringa);
  23.   for ($i = 0; $i < $ln; $i++)
  24.   {
  25.       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"))      
  26.       {
  27.         $retval = $retval . substr($stringa,$i,1);
  28.       }
  29.   }
  30.   return $retval;
  31.  }
  32.  
  33.  
  34.  
  35.  
  36.  function GetCarCognome($cognome)
  37.  {
  38.    $stcons = GetConsonanti($cognome);
  39.    $stvoc = GetVocali($cognome);
  40.    $ln = strlen($stcons);
  41.    
  42.    if (strlen($stcons) >= 3)
  43.    {
  44.      Return substr($stcons, 0, 3);
  45.    }
  46.    
  47.    if (strlen($stcons) == 2)
  48.    {
  49.      if (strlen($stvoc) == 0)
  50.      {
  51.        Return $stcons . "X";
  52.      }
  53.      
  54.      if (strlen($stvoc) > 0)
  55.      {
  56.        Return $stcons . substr($stvoc, 0, 1);
  57.      }
  58.      
  59.    }  
  60.    
  61.    
  62.    if (strlen($stcons) == 1)
  63.    {
  64.      if (strlen($stvoc) == 0)
  65.      {
  66.        Return "";
  67.      }
  68.      
  69.      if (strlen($stvoc) == 1)
  70.      {
  71.        Return $stcons . $stvoc . "X";
  72.      }
  73.      
  74.      if (strlen($stvoc) > 1)
  75.      {
  76.        Return $stcons . substr($stvoc,0,2);
  77.      }    
  78.      
  79.    }  
  80.  
  81.  }
  82.  
  83.  
  84.  
  85.  function GetCarNome($nome)
  86.  {
  87.    $stcons = GetConsonanti($nome);
  88.    $stvoc = GetVocali($nome);
  89.    if (strlen($stcons) >= 4)
  90.    {
  91.      Return substr($stcons, 0,1) . substr($stcons, 2,1) . substr($stcons,3,1);
  92.    }
  93.    
  94.    
  95.    if (strlen($stcons) == 3)
  96.    {
  97.      Return $stcons;
  98.    }    
  99.    
  100.    
  101.    
  102.    if (strlen($stcons) == 2)
  103.    {
  104.      if (strlen($stvoc) == 0)
  105.      {
  106.        Return $stcons . "X";
  107.      }
  108.      
  109.      if (strlen($stvoc) >= 1)
  110.      {
  111.        Return $stcons . substr($stvoc,0,1);
  112.      }
  113.      
  114.    }  
  115.    
  116.    
  117.    if (strlen($stcons) == 1)
  118.    {
  119.      if (strlen($stvoc) == 0)
  120.      {
  121.        Return "";
  122.      }
  123.      
  124.      if (strlen($stvoc) == 1)
  125.      {
  126.        Return $stcons . $stvoc . "X";
  127.      }
  128.      
  129.      if (strlen($stvoc) > 1)
  130.      {
  131.        Return $stcons . substr($stvoc,0,2);
  132.      }    
  133.      
  134.    }  
  135.  
  136.  }
  137.  
  138.  
  139.  
  140. function Calcola($par1,$par2,$par3, $par4, $par5)
  141.  {
  142.  
  143.    $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);
  144.  
  145.    $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);
  146.    
  147.    $basta = False;
  148.    $nc = 0;
  149.    $nv = 0;
  150.    
  151.    $par1 = str_replace("'", "", $par1);
  152.    $par1 = str_replace(" ", "", $par1);
  153.    $par1 = trim($par1);
  154.    
  155.    $par2 = str_replace("'", "", $par2);
  156.    $par2 = str_replace(" ", "", $par2);
  157.    $par2 = trim($par2);
  158.    
  159.    $par1 = strtoupper($par1);
  160.    $par2 = strtoupper($par2);
  161.    
  162.    
  163.    if (strlen($par1) <= 1)
  164.    {
  165.      Return "";
  166.    }  
  167.    
  168.    if (strlen($par2) <= 1)
  169.    {
  170.      Return "";
  171.    }  
  172.    
  173.    
  174.    $letterecognome = GetCarCognome($par2);
  175.  
  176.    
  177.    $letterenome = GetCarNome($par1);
  178.    
  179.    $rst = $letterecognome . $letterenome;
  180.    
  181.    $par3 = trim($par3);    
  182.    
  183.    if(strtotime($par3))
  184.    {
  185.       $data = strtotime($par3);
  186.    } else {
  187.      Return "";
  188.    }
  189.    
  190.    
  191.    
  192.    
  193.    $anno = date("y", $data);
  194.    $stanno = strval($anno);
  195.    
  196.    
  197.    $stmese = date("m", $data);
  198.    $mese = intval($stmese);
  199.    
  200.    $sesso = trim($par4);
  201.    $sesso = strtoupper($sesso);
  202.    
  203.    if (($sesso == "F") or ($sesso == "M"))
  204.    {
  205.      
  206.    } else  {
  207.      Return "";
  208.    }
  209.    
  210.    $codice = trim($par5);
  211.    $codice = $par5;
  212.    
  213.  
  214.    
  215.    if ($mese == 1)
  216.    {
  217.      $stmese = "A";
  218.    }  
  219.    if ($mese == 2)
  220.    {
  221.      $stmese = "B";
  222.    }  
  223.    if ($mese == 3)
  224.    {
  225.      $stmese = "C";
  226.    }    
  227.    if ($mese == 4)
  228.    {
  229.      $stmese = "D";
  230.    }  
  231.    if ($mese == 5)
  232.    {
  233.      $stmese = "E";
  234.    }    
  235.    if ($mese == 6)
  236.    {
  237.      $stmese = "H";
  238.    }  
  239.    if ($mese == 7)
  240.    {
  241.      $stmese = "L";
  242.    }  
  243.    if ($mese == 8)
  244.    {
  245.      $stmese = "M";
  246.    }  
  247.    if ($mese == 9)
  248.    {
  249.      $stmese = "P";
  250.    }    
  251.    if ($mese == 10)
  252.    {
  253.      $stmese = "R";
  254.    }    
  255.    if ($mese == 11)
  256.    {
  257.      $stmese = "S";
  258.    }    
  259.    if ($mese == 12)
  260.    {
  261.      $stmese = "T";
  262.    }
  263.    
  264.    
  265.    $stgiorno = date("d", $data);
  266.  
  267.    
  268.    $giorno = intval($stgiorno);
  269.    
  270.    If ($sesso == "F")
  271.    {
  272.      $giorno = $giorno + 40;  
  273.    }
  274.    
  275.  
  276.    $stgiorno = strval($giorno);
  277.    
  278.    $rst = $rst . $stanno . $stmese . $stgiorno . $codice;
  279.    
  280.    $sommapari = 0;
  281.    $sommadispari = 0;
  282.    $sommatotale = 0;
  283.    $c = 1;
  284.    
  285.    for ($i = 0; $i <= 14; $i++)
  286.    {  
  287.    
  288.    
  289.      $intero = ord(strtoupper(substr($rst,$i,1))) - ord("0");
  290.      if (($c % 2) == 0)
  291.      {
  292.        $sommatotale = $sommatotale + $ValoriPari[$intero];    
  293.      
  294.      } else {
  295.        
  296.        $sommatotale = $sommatotale + $ValoriDispari[$intero];
  297.        
  298.      }
  299.      
  300.      $c = $c + 1;
  301.      
  302.    }
  303.    
  304.    
  305.    $IntCodice = ($sommatotale % 26) + ord("A");
  306.  
  307.    
  308.    $rst = $rst . chr($IntCodice);
  309.    
  310.    Return $rst;
  311.  }
  312.  
  313.  
  314.  
  315. ?>
  316.  
  317.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement