PHP code example of chesszebra / portable-game-notation
1. Go to this page and download the library: Download chesszebra/portable-game-notation 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/ */
chesszebra / portable-game-notation example snippets
use ChessZebra\PortableGameNotation\Reader\StringReader;
$reader = new StringReader('1. e4 e5');
$tokenIterator = $reader->read();
use ChessZebra\PortableGameNotation\Reader\StringReader;
$reader = new StreamReader(fopen('games.pgn', 'r'));
$tokenIterator = $reader->read();
use ChessZebra\PortableGameNotation\TokenIterator;
use ChessZebra\PortableGameNotation\Token\StandardAlgebraicNotation;
use ChessZebra\PortableGameNotation\Writer\StringWriter;
use ChessZebra\StandardAlgebraicNotation\Notation;
$tokenIterator = new TokenIterator([
new MoveNumber(1),
new StandardAlgebraicNotation(new Notation('e4')),
]);
$writer = new StringWriter();
$writer->write($tokenIterator);
$pgn = $writer->getPgn();
use ChessZebra\PortableGameNotation\TokenIterator;
use ChessZebra\PortableGameNotation\Token\StandardAlgebraicNotation;
use ChessZebra\PortableGameNotation\Writer\Stream;
use ChessZebra\StandardAlgebraicNotation\Notation;
$tokenIterator = new TokenIterator([
new MoveNumber(1),
new StandardAlgebraicNotation(new Notation('e4')),
]);
$writer = new Stream(fopen('game.pgn', 'w'));
$writer->write($tokenIterator);
use ChessZebra\PortableGameNotation\Lexer\StringLexer;
$lexer = new StringLexer('1. e4');
$token = $lexer->getNextToken();
use ChessZebra\PortableGameNotation\Lexer\StreamLexer;
$lexer = new StreamLexer(fopen('my-games.pgn', 'r'));
$token = $lexer->getNextToken();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.