chemaclass/edifact-parser

An EDIFACT file parser to extract the values from any defined segment

5.1.0 2025-04-30 10:44 UTC

README

Scrutinizer Code Quality Type Coverage CI PHP Version

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 a UNT 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

🀝 Contributing

We welcome contributions of all kindsβ€”bug fixes, ideas, and improvements.

πŸ“‹ See the contributing guide to get started.