"), array("&", "<", ">"), $pgnText); return $pgnText; } $pgnText = get_pgnText($pgnData); $numGames = preg_match_all("/(\s*\[\s*(\w+)\s*\"([^\"]*)\"\s*\]\s*)+[^\[]*/", $pgnText, $games ); $gameNum = get_param("gameNum", "gn", ""); $expiresDate = ""; if ($gameNum == "random") { $gameNum = rand(1, $numGames); } else if (!preg_match("/^\d+$/", $gameNum)) { $timeNow = time(); $expiresDate = gmdate("D, d M Y H:i:s", (floor($timeNow / (60 * 60 * 24)) + 1) * (60 * 60 * 24)) . " GMT"; if (!preg_match("/^[ +-]\d+$/", $gameNum)) { $gameNum = 0; } // space is needed since + is urldecoded as space $gameNum = floor(($gameNum + ($timeNow / (60 * 60 * 24))) % $numGames) + 1; } else if ($gameNum < 1) { $gameNum = 1; } else if ($gameNum > $numGames) { $gameNum = $numGames; } $gameNum -= 1; header("content-type: application/x-chess-pgn"); header("content-disposition: inline; filename=game.pgn"); if ($expiresDate) { header("expires: " . $expiresDate); } print $games[0][$gameNum]; ?>