Results 1 to 6 of 6

Thread: Number of lines in a file?

  1. #1

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935

    Number of lines in a file?

    Other than iterating through each line and incrementing a counter (seems too resource-intensive), how can I find out how many lines are in a certain file?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
    $file = file('yourfile');
    $x = count($file);
    
    echo $x . ' lines in the file.'
    Or something to that extent.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    Cool

    BTW...
    PHP Code:
    echo $x ' lines in the file.' 
    ...can be replaced with...
    PHP Code:
    echo "$x lines in the file." 

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    ah, nice to know.

    Code:
    //I should use the php tags, huh?
    $file = file('yourfile');
    $x = count($file);
    
    echo $x . ' lines in the file.'
    could probably be replace with:

    Code:
    echo count(file('yourfile')) . ' lines in the file.'
    Althought I haven't tried it
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    Probably could, very C++/Java-like if it works

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    FYI, just tried it. Works like a charm.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width