Good day. I wanted to try to count the number of lines of code in my project. Well, just for fun. The project consists of php pages and functions. Thought to do just through

function countFileLines($file) { return count(file($file)); } 

but it seems like after that there will be a lot of space in the RAM to be engaged. I want to ask for advice. How can this be implemented? Thank you in advance.

    1 answer 1

    The most economical option in memory :-)

     while( ($ch = fgetc($fh)) !== false ) { if( $ch == '\n' ) $lines++; } 

    So or:

     while( ($line = fgets($fh)) !== false ) { $lines++; } 
    • $ fh is the file itself? Is it possible to do something else so that the code itself finds the files on the server? Do not drive a list of the names of all the files, but he himself walked through everything in the home directory? - Emil Sabitov
    • one
      Everything is possible, for this you need to at least try reading a PHP tutorial. - user6550