You may choose whatever memory size you want for the interpreter. iname '.php' This will count the lines in all php-files in the current directory and also subdirectories. Linux or OS X) you can write the following into your Bash shell: wc -l find. If($handle) $linecount = substr_count($handle, PHP_EOL) 7 Answers Sorted by: 106 On a POSIX operating system (e.g. PHP program to count the number of lines in a text file : mytextfile mytextfile.txt alllines file(mytextfile) numberoflines count(. However, if one have no problem with the memory available on the host system, like the OP, and proper memory limit in PHP is set (larger than the file length), substr_count can search the entire content of file with much performance: (2<<24)+(filesize($file)) ) // 32 MB for PHP + File size The code is taking into consideration the use of least memory (2 MB chunks).Ä«enchmark with a 85 MB file and 8M+ lines, execution time is: $linecount += substr_count($chunk,"\n") // also with \n, \r, or \r\n It also returns FALSE if there is no more data to be read. The function stops reading after reaching a specified length, encountering a new line or reaching the end of file. This question does not meet Stack Overflow guidelines. For example, the value of LINE depends on the line that it's used on in your script. Example 1 fseek () example
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |