PHP code example of ivanomatteo / codice-fiscale

1. Go to this page and download the library: Download ivanomatteo/codice-fiscale library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ivanomatteo / codice-fiscale example snippets

 php
include __DIR__.'/vendor/autoload.php';

use IvanoMatteo\CodiceFiscale\CodiceFiscale;


try{

    // will raise an exception if the format is not valid
    $c = CodiceFiscale::parse("RSSMRAULRL1H50MM",1900); // passing the "century" arg, help to validate in case of leap years
    $c = CodiceFiscale::parse("RSSMRAULRL1H50MM");

    echo "\n"."matchName ".($c->matchName('Mario')? 'si' : 'no');
    echo "\n"."isOmocodia ".($c->isOmocodia()? 'si' : 'no');

    // to extract the date of birth, the "century" argumenti is $c->getProbableDateOfBirth(18,'2019-01-01')->format('Y-m-d');

}catch(\Exception $ex){
  echo $ex->getMessage();
}


//
// calculate using person data 
//
$name = 'Mario';
$familyName = 'Rossi';
$dateOfBirth = '1980-10-01';
$sex = 'M';
$cityCode = 'H501';

$cf = CodiceFiscale::calculate($name, $familyName, $dateOfBirth, $sex, $cityCode);

//
// calcumate using an array (it accept an object as well)
//
$person = [
    'name' => $name,
    'familyName' => $familyName,
    'date' => $dateOfBirth,
    'sex' => $sex,
    'cityCode' => $cityCode,
];
$map = [  // it possible to provide a map, to match fields with different names
    'dateOfBirth' => 'date'
];
$cfx = CodiceFiscale::calculateObj($person, $map);


// generate all the 127 possible "omocodia" variations
$variazioni = $cf->generateVariations();

// generate variation n. 7 only
$variazioni = $cf->generateVariations(7);