mustelaitatsi / mrzparser
A PHP package for MRZ parsing.
2.1.3
2025-04-15 06:25 UTC
Requires
- php: ^8.1
- ext-ctype: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.65
- infection/infection: ^0.29.8
- phpmd/phpmd: ^2.15
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5 || ^11.0
- shipmonk/composer-dependency-analyser: ^1.8
README
A PHP package for MRZ parsing.
I needed a method to parse mrz for a project. Unfortunately, many other mrz parsers for php either had the country decoded (I prefer to work with alpha3 codes rather than country names), few/no tests or even look abandoned.
That's why I wrote a small lib that takes care of this.
Installation
You can install the package via composer:
composer require mustelaitatsi/mrzparser
Usage
require 'vendor/autoload.php';
$mrz = 'I<UTOD231458907<<<<<<<<<<<<<<<7408122F1204159UTO<<<<<<<<<<<6ERIKSSON<<ANNA<MARIA<<<<<<<<<<';
$document = MustelaItatsi\MrzParser\Facades\ParserFacade::parseMrz($mrz);
$document->getMrzType() => MustelaItatsi\MrzParser\Enums\MrzType::TD1,
$document->getDocumentCode() => 'I',
$document->getIssuingStateOrOrganization() => 'UTO',
$document->getPrimaryIdentifier() => 'ERIKSSON',
$document->getSecondaryIdentifier() => 'ANNA MARIA',
$document->getDocumentNumber() => 'D23145890',
$document->getNationality() => 'UTO',
$document->getDateOfBirth() => '740812',
$document->getDateOfBirthWithEstimatedEpoch() => '1974-08-12',
$document->getSex() => 'F',
$document->getDateOfExpiry() => '120415',
$document->getDateOfExpiryWithEstimatedEpoch() => '2012-04-15',
$document->getCheckDigits() => [
'documentNumber' => [
'value' => 7,
'calculated' => 7,
'isValid' => true,
],
'dateOfBirth' => [
'value' => 2,
'calculated' => 2,
'isValid' => true,
],
'dateOfExpiry' => [
'value' => 9,
'calculated' => 9,
'isValid' => true,
],
'overall' => [
'value' => 6,
'calculated' => 6,
'isValid' => true,
],
]
Testing
composer test