PHPackages                             chesszebra/portable-game-notation - 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. chesszebra/portable-game-notation

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

chesszebra/portable-game-notation
=================================

A PHP library to parse and write chess games in the portable game notation (PGN) format.

1.1.1(4y ago)29193MITPHPPHP ^7.1

Since Oct 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/chesszebra/portable-game-notation)[ Packagist](https://packagist.org/packages/chesszebra/portable-game-notation)[ RSS](/packages/chesszebra-portable-game-notation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

portable-game-notation
======================

[](#portable-game-notation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bc03db149aeb733e69676d462fa0148a41195a47cf9a0e045fc4013f79c1f486/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63686573737a656272612f706f727461626c652d67616d652d6e6f746174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chesszebra/portable-game-notation)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/58d21453f65f64f17a42a53b1a000e6094bdf041e8e0234d12bf51921e6eca0c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63686573737a656272612f706f727461626c652d67616d652d6e6f746174696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/chesszebra/portable-game-notation)[![Coverage Status](https://camo.githubusercontent.com/d70876ad2d293047b5e61e768e0d5ac043159164c7ad544ee29f6b6262411466/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f63686573737a656272612f706f727461626c652d67616d652d6e6f746174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/chesszebra/portable-game-notation/code-structure)[![Quality Score](https://camo.githubusercontent.com/c5e5c581a165de885c6fedcb933f1a9a9e93ac39a4c48ddd24c3701ea3c27642/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f63686573737a656272612f706f727461626c652d67616d652d6e6f746174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/chesszebra/portable-game-notation)[![Total Downloads](https://camo.githubusercontent.com/00bad4ae71215544cf0d48d7c77244a6b12d873e13681a51d8b06ed390e57c0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63686573737a656272612f706f727461626c652d67616d652d6e6f746174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chesszebra/portable-game-notation)

A PHP library to parse and write chess games in the portable game notation (PGN) format.

Installation
------------

[](#installation)

Via composer

```
composer require chesszebra/portable-game-notation

```

Usage
-----

[](#usage)

### Reading

[](#reading)

#### From a string

[](#from-a-string)

Reading a single PGN game from a string:

```
use ChessZebra\PortableGameNotation\Reader\StringReader;

$reader = new StringReader('1. e4 e5');

$tokenIterator = $reader->read();
```

#### From a stream

[](#from-a-stream)

Reading a single PGN game from a stream:

```
use ChessZebra\PortableGameNotation\Reader\StringReader;

$reader = new StreamReader(fopen('games.pgn', 'r'));

$tokenIterator = $reader->read();
```

### Writing

[](#writing)

#### To a string

[](#to-a-string)

Wriring a PGN game to a string:

```
use ChessZebra\PortableGameNotation\TokenIterator;
use ChessZebra\PortableGameNotation\Token\StandardAlgebraicNotation;
use ChessZebra\PortableGameNotation\Writer\StringWriter;
use ChessZebra\StandardAlgebraicNotation\Notation;

$tokenIterator = new TokenIterator([
    new MoveNumber(1),
    new StandardAlgebraicNotation(new Notation('e4')),
]);

$writer = new StringWriter();
$writer->write($tokenIterator);

$pgn = $writer->getPgn();
```

#### To a stream

[](#to-a-stream)

Wriring a PGN game to a stream:

```
use ChessZebra\PortableGameNotation\TokenIterator;
use ChessZebra\PortableGameNotation\Token\StandardAlgebraicNotation;
use ChessZebra\PortableGameNotation\Writer\Stream;
use ChessZebra\StandardAlgebraicNotation\Notation;

$tokenIterator = new TokenIterator([
    new MoveNumber(1),
    new StandardAlgebraicNotation(new Notation('e4')),
]);

$writer = new Stream(fopen('game.pgn', 'w'));
$writer->write($tokenIterator);
```

### Tokenizing games

[](#tokenizing-games)

#### From a string

[](#from-a-string-1)

```
use ChessZebra\PortableGameNotation\Lexer\StringLexer;

$lexer = new StringLexer('1. e4');

$token = $lexer->getNextToken();
```

#### From a resource

[](#from-a-resource)

```
use ChessZebra\PortableGameNotation\Lexer\StreamLexer;

$lexer = new StreamLexer(fopen('my-games.pgn', 'r'));

$token = $lexer->getNextToken();
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please report them via [HackerOne](https://hackerone.com/chesszebra).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~318 days

Recently: every ~398 days

Total

6

Last Release

1536d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ee7f711ef4d45ada0ac92c7ab2f548055a7cfbe718da6c4bbb81b2f6693c528?d=identicon)[waltertamboer](/maintainers/waltertamboer)

---

Top Contributors

[![waltertamboer](https://avatars.githubusercontent.com/u/508054?v=4)](https://github.com/waltertamboer "waltertamboer (14 commits)")

---

Tags

chesslexerparserpgnphpportable-game-notationreaderwriter

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/chesszebra-portable-game-notation/health.svg)

```
[![Health](https://phpackages.com/badges/chesszebra-portable-game-notation/health.svg)](https://phpackages.com/packages/chesszebra-portable-game-notation)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M282](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M343](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

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

PHPackages © 2026

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