It seems that no function is found to directly obtain the number of objects. Can I only count rows by row? If the system (& quot; wc-l file name & quot;) for large files is efficient, it seems that no function is found to directly obtain the number of file lines.
Can I only count rows by row?
Is the direct sys ("wc-l file name") of large files more efficient?
Reply content:
It seems that no function is found to directly obtain the number of objects.
Can I only count rows by row?
Is the direct sys ("wc-l file name") of large files more efficient?
Small files directly$ Line = count (file ('filename '))
;
Large files can be usedSplFileObject
Processing.
Row-by-row counting slows down when the number of rows is large. For example, if you use fgets to read a row by default, each row generates function call overhead.
You can use substr_count ($ str, "\ n") to count the number of carriage returns.
For large files, you can read 1 MB segments each time, then use substr_count to count the number of trips, and then accumulate the results.