Fix bug in parser when there are hidden chars at beginning of pgn

This commit is contained in:
Alf Magne Kalleland
2019-07-06 22:05:35 +02:00
parent 1586531863
commit d3773ab4fb
3 changed files with 3160 additions and 0 deletions

View File

@@ -83,6 +83,7 @@ class PgnParser
$c = str_replace("0-0-0", "O-O-O", $c);
$c = str_replace("0-0", "O-O", $c);
$c = preg_replace('/^([^\[])*?\[/', '[', $c);
return $c;
}
@@ -102,12 +103,16 @@ class PgnParser
$ret = array();
$content = "\n\n" . $pgn;
$games = preg_split("/\n\n\[/s", $content, -1, PREG_SPLIT_DELIM_CAPTURE);
file_put_contents("parsed.pgn", $content);
for ($i = 1, $count = count($games); $i < $count; $i++) {
$gameContent = trim("[" . $games[$i]);
if (strlen($gameContent) > 10) {
array_push($ret, $gameContent);
}
}
return $ret;
}