- $file = new SplFileObject('/path/to/file.txt');
如何在SplFileObject
中找到文件中的行数?
为什么不简单地使用文件处理程序并在
this question中执行?它简单,快速,高效.
如果你绝对必须使用spl,你可以这样做
- $file = new SplFileObject("/path/to/file.txt");
- $i = 0;
- while (!$file->eof()) {
- $i++;
- $file->next();
- }
- print "file has " . $i . " lines";