Getting the Number of Lines in a File : count « Data Structure « PHP






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.";
  }
  
?>
  
  








Related examples in the same category

1.Counting Array Elements
2.Get the size of an array in PHP using the count() function
3.Using count() to Iterate Through an Array