user27007: I'm sending a request to the chess.com API to https://api.chess.com/pub/player/hikaru/games/2021/03
It will return all the games played by Hikaru in March of 2021, the interesting data is in the PGN key, however it seems to be stored in a string making parsing and extracting the data relatively difficult.
I am currently using PHP to send my curl request but I can't find a reliable way to parse the data within the PGN key to extract data like, opening, Elo, and most importantly the actual moves.
I considered using a regex which would work in most cases, but I worry the problems that may occur with a weird username.

user15619: Parsing PGN string is quite straightforward, as you can simply follow the specification [Wikipedia alternative], and you can do it manually by processing it line by line.
There are already existing libraries that do this, for example, since you are using PHP, this is one PGN parser in PHP: https://github.com/amyboyd/pgn-parser

27007: <p>I'm sending a request to the chess.com API to <a href="https://api.chess.com/pub/player/hikaru/games/2021/03" rel="nofollow noreferrer">https://api.chess.com/pub/player/hikaru/games/2021/03</a></p>
<p>It will return all the games played by Hikaru in March of 2021, the interesting data is in the PGN key, however it seems to be stored in a string making parsing and extracting the data relatively difficult.</p>
<p>I am currently using PHP to send my curl request but I can't find a reliable way to parse the data within the PGN key to extract data like, opening, Elo, and most importantly the actual moves.</p>
<p>I considered using a regex which would work in most cases, but I worry the problems that may occur with a weird username.</p>
 15619: <p>Parsing PGN string is quite straightforward, as you can simply follow <a href="http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm" rel="nofollow noreferrer">the specification</a> [<a href="https://en.wikipedia.org/wiki/Portable_Game_Notation" rel="nofollow noreferrer">Wikipedia alternative</a>], and you can do it manually by processing it line by line.</p>
<p>There are already existing libraries that do this, for example, since you are using PHP, this is one PGN parser in PHP: <a href="https://github.com/amyboyd/pgn-parser" rel="nofollow noreferrer">https://github.com/amyboyd/pgn-parser</a></p>
