If you want to load the full-content of a file to a PHP variable, the easiest (and, probably fastest) way would be file_get_contents
.
But, if you are working with big files, loading the whole file into memory might not be such a good idea : you'll probably end up with a memory_limit
error, as PHP will not allow your script to use more than (usually) a couple mega-bytes of memory.
So, even if it's not the fastest solution, reading the file line by line (fopen
+fgets
+fclose
), and working with those lines on the fly, without loading the whole file into memory, might be necessary...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…