EDIFACT stands for Electronic Data Interchange For Administration, Commerce, and Transport.
This package provides a robust and extensible PHP parser to read, interpret, and extract data from EDIFACT-formatted files.
🔍 Not sure what EDIFACT is? Learn more here
- A file is composed of multiple segments—each begins with a tag (e.g.,
UNH
,NAD
). - Each segment contains structured data relevant to that tag.
- A message typically starts with a
UNH
segment and ends with aUNT
segment. - A transaction is a list of such messages within a file.
👉 Read more about segments here
Install via Composer:
composer require chemaclass/edifact-parser
<?php declare(strict_types=1);
use EdifactParser\EdifactParser;
require dirname(__DIR__) . '/vendor/autoload.php';
$fileContent = <<<EDI
...
NAD+CN+++Person Name+Street Nr 2+City2++12345+DE'
...
EDI;
$parser = EdifactParser::createWithDefaultSegments();
$parserResult = $parser->parse($fileContent);
// Or directly from a file
//$parserResult = $parser->parseFile('/path/to/file.edi');
$firstMessage = $parserResult->transactionMessages()[0];
$nadSegment = $firstMessage->segmentByTagAndSubId('NAD', 'CN');
$personName = $nadSegment->rawValues()[4]; // 'Person Name'
- example/printing-segments.php — Print all parsed segments line by line.
- example/extracting-data.php — Extract values from specific segments.
- example/context-segments.php — Traverse hierarchical context segments.
We welcome contributions of all kinds—bug fixes, ideas, and improvements.
📋 See the contributing guide to get started.