Home / PHP Tips Generated By ChatGPT / Basic File Reading Line by Line in PHP Read a file line by line with fgets(). Source Code $file = fopen("test.txt", "r"); if ($file) { while (($line = fgets($file)) !== false) { echo $line; } fclose($file); }