dominikveils / pgn-parser
Simple PGN parser
Installs: 91
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/dominikveils/pgn-parser
Requires (Dev)
- phpunit/phpunit: ^6.1
This package is not auto-updated.
Last update: 2025-10-26 09:19:37 UTC
README
PHP parser for PGN format
Install
$ composer require dominikveils/pgn-parser
Usage
<?php require 'vendor/autoload.php'; $parser = new DominikVeils\PGNParser\PGNParser; $pgn = "... pgn string"; $games = $parser->fromString($pgn); // Now $games is array of DominikVeils\PGNParser\Game objects foreach ($games as $game) { // Do your staff here // Each game could be converted into a JSON string or just an array $game_json = $game->toJSON(); $game_array = $game->toArray(); }
Example JSON output
{
"metadata":[
{
"name":"event",
"value":"Lloyds Bank op"
},
{
"name":"site",
"value":"London"
},
{
"name":"date",
"value":"1984.??.??"
},
{
"name":"round",
"value":"1"
},
{
"name":"white",
"value":"Adams, Michael"
},
{
"name":"black",
"value":"Sedgwick, David"
},
{
"name":"result",
"value":"1-0"
},
{
"name":"whiteelo",
"value":""
},
{
"name":"blackelo",
"value":""
},
{
"name":"eco",
"value":"C05"
}
],
"moves":[
{
"number":1,
"white":"e4",
"black":"e6"
},
{
"number":2,
"white":"d4",
"black":"d5"
},
{
"number":3,
"white":"Nd2",
"black":"Nf6"
},
// ...
]
}
Test
$ vendor/bin/phpunit
TODO
- Add comments support
License
MIT