mustelaitatsi / mrzparser
A PHP package for MRZ parsing.
2.2.0
2026-03-26 20:45 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,
],
]
API Stability
Only ParserFacade::parseMrz() and DocumentInterface are stable public contracts. Downstream
consumers should depend only on these two. All other classes, enum cases, and interfaces are
internal implementation details and may change in any release without notice.
Testing
composer test