I want to read a file and process its content line by line.
What I came up with:
Code: Select all
$fileContent = readfile("[path]");
foreach($line, $fileContent, "<crlf>", "e") //"e" to skip empty lines
{
//do something with $line
}E.g.is <crlf> one character or 2? The help file looks like it was one ("<crlf> Carriage Return Line Feed (0x0D0A)").
But what if the line "seperators" are made up of only "cr" character or only "lf" character? Or if <crlf> is one char what if the file contains cr + lf as 2 chars on each line?
Or maybe there is a faster way for large files?? I don't know, I am asking.
Besides, are there any other pitfalls that one could fall into with the code I posted? (Don't take this last question too literally. Read between the words, please.
EDIT: Related, that I have looked at, e.g.: How to read UNICODE file content with readfile()?
XYplorer Beta Club