PHP code example of nepada / birth-number

1. Go to this page and download the library: Download nepada/birth-number 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/ */

    

nepada / birth-number example snippets


$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('0421010030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101 0030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101 / 0030');

echo((string) $birthNumber); // '042101/0030'
echo($birthNumber->toString()); // '042101/0030'
echo($birthNumber->toStringWithoutSlash()); // '0421010030'

Nepada\BirthNumber\BirthNumber::isValid('0421010030'); // true
Nepada\BirthNumber\BirthNumber::isValid('9999999999'); // false

$birthNumber1 = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber2 = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber1->equals($birthNumber2); // true

$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('047101 / 0090');
$birthNumber->getBirthDate(); // \DateTimeImmutable('2004-01-01')

$gender = $birthNumber->getGender(); // Nepada\BirthNumber\Gender enum instance
$gender->isFemale(); // true
$gender->isMale(); // false
$gender->toString(); // 'female'