Getting the Number of Lines in a File : count « Data Structure « PHP
- PHP
- Data Structure
- count
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