mustelaitatsi/mrzparser

A PHP package for MRZ parsing.

Maintainers

Package info

gitlab.com/MustelaItatsi/MrzParser

Issues

pkg:composer/mustelaitatsi/mrzparser

Statistics

Installs: 17 396

Dependents: 0

Suggesters: 0

Stars: 0

2.2.0 2026-03-26 20:45 UTC

This package is auto-updated.

Last update: 2026-03-26 20:49:23 UTC


README

Pipeline Status Latest Version on Packagist Total Downloads Coverage Mutation testing badge

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