Count the number of lines in a file


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Count number of lines in a file.
  3.  *
  4.  * @access private
  5.  * @param string filepath : The name of the file
  6.  * @return int : The number of lines
  7.  */
  8. private function _count_lines($file)
  9. {
  10. $handle = fopen( $filepath, "r" );
  11. $count = 0;
  12. while(fgets($handle))
  13. {
  14. $count++;
  15. }
  16. fclose($handle);
  17. return $count;
  18. } // End of _count_lines

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.