2017 © Pedro Peláez
 

library pgn-parser

Simple PGN parser

image

dominikveils/pgn-parser

Simple PGN parser

  • Saturday, April 22, 2017
  • by dominikveils
  • Repository
  • 2 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 33 % Grown

The README.md

PGNParser Build Status

PHP parser for PGN format, (*1)

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, (*2)

The Versions

22/04 2017

dev-master

9999999-dev

Simple PGN parser

  Sources   Download

MIT

The Development Requires

by Dominik Veils

22/04 2017

1.0.1

1.0.1.0

Simple PGN parser

  Sources   Download

MIT

The Development Requires

by Dominik Veils

22/04 2017

1.0.0

1.0.0.0

Simple PGN parser

  Sources   Download

MIT

The Development Requires

by Dominik Veils