Skip to content

Chemaclass/edifact-parser

Repository files navigation

📦 EDIFACT Parser

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;

$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'

📂 More Examples

🤝 Contributing

We welcome contributions of all kinds—bug fixes, ideas, and improvements.

📋 See the contributing guide to get started.

About

A parser for a UN/EDIFACT file in PHP

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Contributors 3

  •  
  •  
  •