Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/Chemaclass/edifact-parser

A parser for a UN/EDIFACT file in PHP
https://github.com/Chemaclass/edifact-parser

edi edifact parser php

Last synced: 10 days ago
JSON representation

A parser for a UN/EDIFACT file in PHP

Lists

README

        

# EDIFACT Parser

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Chemaclass/EdifactParser/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Chemaclass/EdifactParser/?branch=master)
[![Type Coverage](https://shepherd.dev/github/Chemaclass/EdifactParser/coverage.svg)](https://shepherd.dev/github/chemaclass/EdifactParser)
[![CI](https://github.com/Chemaclass/EdifactParser/workflows/CI/badge.svg?branch=master)](https://github.com/Chemaclass/EdifactParser/actions)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg?style=flat-square)](https://php.net/)

EDIFACT stands for `Electronic Data Interchange For Administration, Commerce, and Transport`.

This repository contains a parser for any EDIFACT file to extract the values from any segment
defined in an EDIFACT formatted file.

Ok, but... [What is EDIFACT?](/docu/README.md)

## Format of an EDIFACT file

* Each line of the file consists of a set of data that belongs to a specific segment of a message.

* A segment is defined by a tag. Following the rest of the data that belongs to that segment. More about segments [here](/docu/segments/README.md).

* A message is a list of segments. Usually, all segments between the UNH and UNT segments compound a message.

* A transaction is the list of messages that belongs to a file.

### Installation

```bash
composer require chemaclass/edifact-parser
```

### Contribute

You are more than welcome to contribute reporting
[issues](https://github.com/gacela-project/gacela/issues),
sharing [ideas](https://github.com/gacela-project/gacela/discussions),
or [contributing](.github/CONTRIBUTING.md) with your Pull Requests.

### Basic examples

You can see a full example of [printing segments](example/printing-segments.php).

You can see a full example of [extracting data](example/extracting-data.php).

```php
parse($fileContent);
$firstMessage = $parserResult->transactionMessages()[0];

$cnNadSegment = $firstMessage->segmentByTagAndSubId('NAD', 'CN');
$personName = $cnNadSegment->rawValues()[4];

var_dump($personName); // 'Person Name'
```