Lines in a file

By log2 on Dec 20, 2004

This is similar to the last one I wrote, but this one tells the person how many lines are in a text file instead of how many files are in a directory. This can be useful on an informational site to forwarn or inform the reader of how to prepare for a long, or short read

<? 

//specify the filename 
$filename = "myfile.txt"; 

$lines    = file($filename); 
$count    = count($lines); 

//show the result 
echo("There are $count lines in the file"); 

?>

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.