PHPackages                             uhin/x12-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. uhin/x12-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

uhin/x12-parser
===============

A library used to parse X12 EDI

2.0.0(1y ago)1772.0k—2.4%16[2 issues](https://github.com/UHIN/x12-parser-library/issues)MITPHPPHP ^8.3

Since Jun 28Pushed 1y ago5 watchersCompare

[ Source](https://github.com/UHIN/x12-parser-library)[ Packagist](https://packagist.org/packages/uhin/x12-parser)[ RSS](/packages/uhin-x12-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (16)Used By (0)

X12 Parser / Serializer
=======================

[](#x12-parser--serializer)

### Including this library

[](#including-this-library)

You'll need to include this library in your project in order to use it. First, add the following to the repositories section of your composer.json file:

```
{
  ...
  "require": {
    ...
    "uhin/x12-parser": "^2.0.0"
    ...
  }
}
```

You can now include the library into your project by running:

```
composer require uhin/x12-parser
```

Once you're included the library in your project, you can now begin writing code to parse and serialize X12 EDI.

### Examples

[](#examples)

##### Parsing a file

[](#parsing-a-file)

```
use Uhin\X12Parser\Parser\X12Parser;

// Load the file into memory
$rawX12 = file_get_contents('path-to-your-file');

// Create a parser object
$parser = new X12Parser($rawX12);

// Parse the file into an object data structure
$x12 = $parser->parse();
// $x12 is now an X12 object containing all of the information from the X12 file
```

Note: If any segment/property can have multiples then it will always be parsed into an array, even if there is only one present. This is to avoid confusion on whether or not you are dealing with an array or an object.

```
// Using the $x12 object from the examlpe above...

// Retrieving the GS06
$gs06 = $x12->ISA[0]->GS[0]->GS06;

// Setting the GS06 value
$x12->ISA[0]->GS[0]->GS06 = 'Changed Value';
```

##### Converting a parsed file back to X12

[](#converting-a-parsed-file-back-to-x12)

```
use Uhin\X12Parser\Serializer\X12Serializer;

// Using the $x12 object from the examlpe above...
$serializer = new X12Serializer($x12);

// Options for serializing:
$serializer->addNewLineAfterSegment(true);
$serializer->addNewLineAfterIEA(true);

// Generate the raw X12 string
$rawX12 = $serializer->serialize();
```

### Unit Tests

[](#unit-tests)

First, make sure that you've placed your test files in the `tests/test-files` directory.

**NOTE:** *Don't commit these files to git if they have any HIPPA data.*

The current tests will look for the following files in the `tests/test-files` directory:

- `837.edi`
- `TA1.edi`

Once you have your files in place, you can run this command from the root of the library:

```
composer install
```

```
./vendor/bin/phpunit
./vendor/bin/phpunit --coverage-html tests/coverage
```

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 54.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~211 days

Recently: every ~460 days

Total

12

Last Release

560d ago

Major Versions

1.0.10 → 2.0.02024-11-04

PHP version history (2 changes)1.0.0PHP &gt;=7.0

2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/899e507c69e61ef15d5532164afe29452d9e06075de3eb1a6265e538c32ac21d?d=identicon)[rmclellanduhin](/maintainers/rmclellanduhin)

---

Top Contributors

[![cameronhejazifar](https://avatars.githubusercontent.com/u/72213537?v=4)](https://github.com/cameronhejazifar "cameronhejazifar (19 commits)")[![zlobato](https://avatars.githubusercontent.com/u/30511504?v=4)](https://github.com/zlobato "zlobato (8 commits)")[![behrhartuhin](https://avatars.githubusercontent.com/u/30664560?v=4)](https://github.com/behrhartuhin "behrhartuhin (2 commits)")[![rmclellanduhin](https://avatars.githubusercontent.com/u/36676665?v=4)](https://github.com/rmclellanduhin "rmclellanduhin (2 commits)")[![markguyver](https://avatars.githubusercontent.com/u/3242128?v=4)](https://github.com/markguyver "markguyver (1 commits)")[![chejaziuhin](https://avatars.githubusercontent.com/u/36676697?v=4)](https://github.com/chejaziuhin "chejaziuhin (1 commits)")[![skiram](https://avatars.githubusercontent.com/u/3024449?v=4)](https://github.com/skiram "skiram (1 commits)")[![kclayton925](https://avatars.githubusercontent.com/u/11861818?v=4)](https://github.com/kclayton925 "kclayton925 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/uhin-x12-parser/health.svg)

```
[![Health](https://phpackages.com/badges/uhin-x12-parser/health.svg)](https://phpackages.com/packages/uhin-x12-parser)
```

###  Alternatives

[driftingly/rector-laravel

Rector upgrades rules for Laravel Framework

1.2k12.0M462](/packages/driftingly-rector-laravel)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[veewee/xml

XML without worries

1835.9M29](/packages/veewee-xml)[laminas/laminas-hydrator

Serialize objects to arrays, and vice versa

12916.8M147](/packages/laminas-laminas-hydrator)[mck89/peast

Peast is PHP library that generates AST for JavaScript code

18934.7M29](/packages/mck89-peast)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
