PHP code example of marcmorente / pgn-parser

1. Go to this page and download the library: Download marcmorente/pgn-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marcmorente / pgn-parser example snippets




NParser\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;
}