chemaclass / edifact-parser
An EDIFACT file parser to extract the values from any defined segment
Fund package maintenance!
chemaclass.com/sponsor
Installs: 3 148
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 4
Forks: 3
Open Issues: 4
Requires
- php: >=8.0
- ext-json: *
- sabas/edifact: ^1.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.57
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.6
- symfony/var-dumper: ^5.4
- vimeo/psalm: ^4.30
This package is auto-updated.
Last update: 2025-05-06 17:32:29 UTC
README
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
π EDIFACT Format Overview
- 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
πΎ Installation
Install via Composer:
composer require chemaclass/edifact-parser
π§ͺ Examples
π Usage example
<?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; $parserResult = EdifactParser::createWithDefaultSegments()->parse($fileContent); $firstMessage = $parserResult->transactionMessages()[0]; $nadSegment = $firstMessage->segmentByTagAndSubId('NAD', 'CN'); $personName = $nadSegment->rawValues()[4]; // 'Person Name'
π More Examples
- example/printing-segments.php β Print all parsed segments line by line.
- example/extracting-data.php β Extract values from specific segments.
π€ Contributing
We welcome contributions of all kindsβbug fixes, ideas, and improvements.
- π Report issues
- π§ Submit a pull request
π See the contributing guide to get started.