Open a connection to a file, using fopen(), and work with that file line by line before you close the resource. Functions for reading each line include fgetc, fgets . Reading a specific line from a file with PHP it's easier to use Google Sheets than it is to build out an admin section) I've had to get creative. You can use the fgets() function to read the file line by line: . php $file = new SplFileObject("ttcih.org"); // Loop until we reach the end of the file. while . fgets can get an error (returnfing false) and loop forever without reaching the end of file. A tutorial on how to read CSV files with PHP. In a CSV file, all values are separated by a comma (hence the meaning behind the acronym: . If you're still a bit confused and you need to get your head around it, be sure to save the example. You can use the PHP newline characters \n or \r\n to create a new line inside the source code. However, if you want the line breaks to be visible in the browser. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient . and do a foreach($lines as $line) so every line did not get duplicated. from reading-files-line-by-linephp function readTheFile($path) of serving up a file from the local file system, we want to get it from a CDN. Reading a File Line by Line. The fgets() function is used to read a single line from a file. Note: After a call to this function the file pointer has moved to the next. You want to read a specific line in a file; for example, you want to read the most recent guestbook entry that's been added on to the end of a guestbook file. The fgets() function returns a line from an open file. The fgets() function stops returning on a new line, at the specified length, or at EOF, whichever comes first.