PHPackages                             risendy/pgn-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. risendy/pgn-parser

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

risendy/pgn-parser
==================

PGN chess notation parser

19[1 issues](https://github.com/risendy/pgn-chess-parser/issues)[1 PRs](https://github.com/risendy/pgn-chess-parser/pulls)PHPCI passing

Since Oct 16Pushed 3w ago1 watchersCompare

[ Source](https://github.com/risendy/pgn-chess-parser)[ Packagist](https://packagist.org/packages/risendy/pgn-parser)[ RSS](/packages/risendy-pgn-parser/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (3)Used By (0)

Table of contents
-----------------

[](#table-of-contents)

- [General info](#general-info)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Tests](#tests)

General info
------------

[](#general-info)

Simple pgn chess notation parser written in PHP. PGN should be in string format, default tags delimiter is newline. There should be at least one blank line between tags and moves because it is used to process the pgn string.

Features
--------

[](#features)

- extracting moves in string/json/array/object array formats
- getting specific moves (black or white)
- getting specific move comment
- getting first/last move
- extracting tags in string format
- getting tags value by name

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

[](#installation)

```
composer require risendy/pgn-parser

```

Usage
-----

[](#usage)

To parse pgn string:

```
$game = new Game();
$game->parsePgn($pgn);

```

To get moves in string format:

```
$moves = $game->getMovesString();

result:
string(15) "e4 e6 d4 d5 0-1"

```

To get moves in json format:

```
$json = $game->createJsonArray();

result:
{
   "tags":{
      "Event":"Lets Play!",
      "Site":"Chess.com",
      "Date":"2018.12.04",
      "Round":"?",
      "White":"guilherme_1910",
      "Black":"bmbio",
      "Result":"0-1",
      "TimeControl":"1\/259200:0"
   },
   "moves":[
      {
         "moveNumber":1,
         "white":"e4",
         "black":"e6"
      },
      {
         "moveNumber":2,
         "white":"d4",
         "black":null
      }
   ]
}

```

To get moves in array format:

```
$moves = $game->getSimpleMovesArray();

result:
array(5) {
  [0]=>
  string(2) "e4"
  [1]=>
  string(2) "e6"
  [2]=>
  string(2) "d4"
  [3]=>
  string(2) "d5"
  [4]=>
  string(3) "0-1"
}

```

To get moves in object array format:

```
$moves = $game->getObjectMovesArray();

result:
array(3) {
  [1]=>
  array(2) {
    [0]=>
    object(PgnParser\Move)#22 (3) {
      ["move":"PgnParser\Move":private]=>
      string(2) "e4"
      ["moveNumber":"PgnParser\Move":private]=>
      int(1)
      ["moveColor":"PgnParser\Move":private]=>
      string(1) "W"
    }
    [1]=>
    object(PgnParser\Move)#23 (3) {
      ["move":"PgnParser\Move":private]=>
      string(2) "e6"
      ["moveNumber":"PgnParser\Move":private]=>
      int(1)
      ["moveColor":"PgnParser\Move":private]=>
      string(1) "B"
    }
  }
  [2]=>
  array(2) {
    [0]=>
    object(PgnParser\Move)#24 (3) {
      ["move":"PgnParser\Move":private]=>
      string(2) "d4"
      ["moveNumber":"PgnParser\Move":private]=>
      int(2)
      ["moveColor":"PgnParser\Move":private]=>
      string(1) "W"
    }
    [1]=>
    object(PgnParser\Move)#25 (3) {
      ["move":"PgnParser\Move":private]=>
      string(2) "d5"
      ["moveNumber":"PgnParser\Move":private]=>
      int(2)
      ["moveColor":"PgnParser\Move":private]=>
      string(1) "B"
    }
  }
  [3]=>
  array(1) {
    [0]=>
    object(PgnParser\Move)#26 (3) {
      ["move":"PgnParser\Move":private]=>
      string(3) "0-1"
      ["moveNumber":"PgnParser\Move":private]=>
      int(3)
      ["moveColor":"PgnParser\Move":private]=>
      string(1) "W"
    }
  }
}

```

To get specific move instance:

```
$move = $game->getMove(2, 'B');

result:
object(PgnParser\Move)#75 (4) {
["san":"PgnParser\Move":private]=>
string(2) "d4"
["moveNumber":"PgnParser\Move":private]=>
int(2)
["moveColor":"PgnParser\Move":private]=>
string(1) "W"
["comment":"PgnParser\Move":private]=>
string(4) "test"

```

To get specific move san:

```
$move = $game->getMove(2, 'B')->getSan();

result:
string(2) "d5"

```

To get specific move comment:

```
$move = $game->getMove(2, 'B')->getComment();

result:
string(4) "test"

```

To get tag value by name:

```
$tagValue = $game->getTagValueByName('Black');

result:
string(5) "bmbio"

```

Tests
-----

[](#tests)

If you want to run tests use:

```
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/PgnParserTest

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance42

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/86e1b687a6301f8577e84eb0a7c3a967ae9c57f75456ab9881ad374b818ac38b?d=identicon)[risendy](/maintainers/risendy)

---

Top Contributors

[![risendy](https://avatars.githubusercontent.com/u/5420748?v=4)](https://github.com/risendy "risendy (10 commits)")

---

Tags

chesspgnpgn-extract

### Embed Badge

![Health badge](/badges/risendy-pgn-parser/health.svg)

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

###  Alternatives

[efficiently/jquery-laravel

This package provides jQuery and the jQuery-ujs driver for your Laravel &gt;= 6 application.

1311.0k1](/packages/efficiently-jquery-laravel)

PHPackages © 2026

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