PHP code example of alcea / cnp
1. Go to this page and download the library: Download alcea/cnp 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/ */
alcea / cnp example snippets
composer
// a\cnp\Cnp;
$cnpToBeValidated = '5110102441483';
$cnp = new Cnp($cnpToBeValidated);
if ($cnp->isValid()) {
// extract information from CNP
echo "CNP {$cnpToBeValidated} - is valid" . PHP_EOL;
echo "Birth Date: {$cnp->getBirthDateFromCNP('Y/m/d')}" . PHP_EOL;
echo "Birth Place: {$cnp->getBirthCountyFromCNP()}" . PHP_EOL;
echo "Gender: {$cnp->getGenderFromCNP('male', 'female')}" . PHP_EOL;
echo "Serial: {$cnp->getSerialNumberFromCNP()}" . PHP_EOL;
echo "Person is " . ($cnp->isPersonMajor() ? '' : 'not' ) . ' major' . PHP_EOL;
echo "Person have an Identity Card " . ($cnp->hasIdentityCard() ? 'YES' : 'NO' );
} else {
echo "CNP {$cnpToBeValidated} is invalid" . PHP_EOL;
}
// or call static
echo "CNP {$cnpToBeValidated} is " . Cnp::validate($cnpToBeValidated) ? 'valid' : 'invalid';