Mega Code Archive

 
Categories / Php / Data Type
 

Getting the Number of Lines in a File

<?php   $afile = "data.txt";   if (file_exists ($afile)){     $rows = file ($afile);     echo count ($rows) . " lines in this file"; //Outputs 4 in this case   } else {     echo "Sorry, file does not exist.";   }    ?>