PHP code example of byrokrat / id

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

    

byrokrat / id example snippets


use byrokrat\id\PersonalId;
use byrokrat\id\IdInterface;

$id = new PersonalId('940323-2383');

// outputs 940323-2383
echo $id;

// outputs 940323-2383
echo $id->format(IdInterface::FORMAT_10_DIGITS);

// outputs 199403232383
echo $id->format(IdInterface::FORMAT_12_DIGITS);

// outputs 940323
echo $id->format('ymd');

// outputs something like 25
echo $id->getAge();

// outputs 1 (true)
echo $id->isFemale();

use byrokrat\id\OrganizationId;
use byrokrat\id\IdInterface;

$id = new OrganizationId('835000-0892');

// outputs 835000-0892
echo $id->format(IdInterface::FORMAT_10_DIGITS);

// outputs 008350000892
echo $id->format(IdInterface::FORMAT_12_DIGITS);

// outputs 1 (true)
echo $id->isSexUndefined();

// outputs 1 (true)
echo $id->isNonProfit();

use byrokrat\id\PersonalIdFactory;
use byrokrat\id\CoordinationIdFactory;

$factory = new PersonalIdFactory(new CoordinationIdFactory);

$id = $factory->createId('940323-2383');

use byrokrat\id\PersonalIdFactory;

$factory = new PersonalIdFactory;

// Year interpreted as 2010 as parsing is done 2020
$young = $factory->createId('1001012382', new \DateTime('20200101'));

// Year interpreted as 1910 as parsing is done 1990
$older = $factory->createId('1001012382', new \DateTime('19900101'));

// outputs 2010
echo $young->format('Y');

// outputs 1910
echo $older->format('Y');

use byrokrat\id\PersonalIdFactory;

$factory = new PersonalIdFactory;

// Delimiter is '+' as parsing is done in 2050
$id = $factory->createId('194001079120', new \DateTime('20500101'));

// outputs 400107+9120
echo $id;

echo $id->format($formatStr);

use byrokrat\id\Formatter\Formatter;
use byrokrat\id\PersonalId;

$formatter = new Formatter('y');

// outputs 82
echo $formatter->format(new PersonalId('940323-2383'));