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

3.1.0(4w ago)1880.2k↓23.8%18[2 issues](https://github.com/UHIN/x12-parser-library/issues)MITPHPPHP ^8.4CI failing

Since Jun 28Pushed 4w 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 2d ago

READMEChangelog (7)Dependencies (8)Versions (21)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

66

—

FairBetter than 99% of packages

Maintenance91

Actively maintained with recent releases

Popularity42

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~207 days

Recently: every ~535 days

Total

15

Last Release

29d ago

Major Versions

1.0.10 → 2.0.02024-11-04

2.1.0 → 3.0.02026-04-23

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

2.0.0PHP ^8.3

3.0.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/36676665?v=4)[rmclellanduhin](/maintainers/rmclellanduhin)[@rmclellanduhin](https://github.com/rmclellanduhin)

---

Top Contributors

[![cameronhejazifar](https://avatars.githubusercontent.com/u/72213537?v=4)](https://github.com/cameronhejazifar "cameronhejazifar (19 commits)")[![jdominguezvirla](https://avatars.githubusercontent.com/u/211859237?v=4)](https://github.com/jdominguezvirla "jdominguezvirla (8 commits)")[![zlobato](https://avatars.githubusercontent.com/u/30511504?v=4)](https://github.com/zlobato "zlobato (8 commits)")[![aik099](https://avatars.githubusercontent.com/u/1277526?v=4)](https://github.com/aik099 "aik099 (2 commits)")[![behrhartuhin](https://avatars.githubusercontent.com/u/30664560?v=4)](https://github.com/behrhartuhin "behrhartuhin (2 commits)")[![chejaziuhin](https://avatars.githubusercontent.com/u/36676697?v=4)](https://github.com/chejaziuhin "chejaziuhin (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)")[![kclayton925](https://avatars.githubusercontent.com/u/11861818?v=4)](https://github.com/kclayton925 "kclayton925 (1 commits)")[![skiram](https://avatars.githubusercontent.com/u/3024449?v=4)](https://github.com/skiram "skiram (1 commits)")[![trbute](https://avatars.githubusercontent.com/u/103962894?v=4)](https://github.com/trbute "trbute (1 commits)")[![kstubbsuhin](https://avatars.githubusercontent.com/u/221588065?v=4)](https://github.com/kstubbsuhin "kstubbsuhin (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.2k15.4M728](/packages/driftingly-rector-laravel)[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k16.6M147](/packages/spatie-laravel-sitemap)[veewee/xml

XML without worries

1837.0M39](/packages/veewee-xml)[statamic/cms

The Statamic CMS Core Package

4.8k3.6M985](/packages/statamic-cms)[laminas/laminas-hydrator

Serialize objects to arrays, and vice versa

13218.1M167](/packages/laminas-laminas-hydrator)[php-soap/wsdl-reader

A WSDL reader in PHP

212.7M18](/packages/php-soap-wsdl-reader)

PHPackages © 2026

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