PHP code example of ion-bazan / nric
1. Go to this page and download the library: Download ion-bazan/nric 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/ */
ion-bazan / nric example snippets
use IonBazan\NRIC\Exception\InvalidChecksumException;
use IonBazan\NRIC\Exception\InvalidFormatException;
use IonBazan\NRIC\NRIC;
$nric = NRIC::generateNric(new DateTime('1990-01-01')); // Generate a random NRIC number
$fin = NRIC::generateFin(new DateTime('1990-01-01')); // Generate a random FIN number
try {
$invalid = NRIC::fromString('S0000001A'); // Create a self-validating (invalid) instance
} catch (InvalidChecksumException|InvalidFormatException $e) {
var_dump('invalid');
}
$valid = NRIC::fromString('S0000001I'); // Create a self-validating instance from valid input
var_dump($valid->__toString()); // Thanks to Stringable interface