Line Counter example

This is a simple line counter example which will count the lines in a text file

<?php
function LineCounter($file)
 {
    /* open the file  */
    $fh = fopen( $file, “r” );

    $count = 0;

    while(fgets($fh))
    {
        $count++;
    }
    fclose($fh);
    return $count;
 }
 
 /*change to a file on your system*/
echo LineCounter(“phonebook.php”);

?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*