marcmorente/pgn-parser

A PHP parser for the chess game notation format - PGN(Portable Game Notation)

Installs: 21

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/marcmorente/pgn-parser

1.0.1 2021-10-05 07:41 UTC

This package is auto-updated.

Last update: 2025-12-05 16:43:05 UTC


README

Install

composer require marcmorente/pgn-parser

Example Code

The code below parses a PGN file and prints the event, name of the white player, name of the black player, result and moves of each game.

<?php

require __DIR__.'/vendor/autoload.php';
use PGNParser\PGN;

$filePath = __DIR__.'/tests/PGNFiles/randomEvents.pgn';
$pgn = new PGN($filePath);
$games = $pgn->getGames();

foreach ($games as $game) {
    echo $pgn->metaData($game)->getEvent(). PHP_EOL;
    echo $pgn->metaData($game)->getWhite(). PHP_EOL;
    echo $pgn->metaData($game)->getBlack(). PHP_EOL;
    echo $pgn->metaData($game)->getResult(). PHP_EOL;
    echo $pgn->getRawMoves($game). PHP_EOL;
    echo PHP_EOL;
}