Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding the Amount of Lines in a file...

    Hello,

    I was wondering, how would I go about finding the amount of lines in a file? I have a file, and it has a lot of stuff. Ex:
    [File]
    55667
    42aklsdf
    aasdkfk6
    3sdjf'as
    39810-4
    mmzjc
    [/file]

    How would I find out that there are 6 lines in this file, using php?

    Thanks,
    l3vi

    Edit:

    Never mind, I called up one of my friends and figured out how to do this If you want to know you use this line of code:

    Code:
     $lines = file ('filename');
     $num_lines = count ($lines);
    
    echo ("Total lines in file: " . $num_lines);
    Last edited by l3vi; 05-01-2004 at 09:46 PM.

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you should note that that may not be suitable to be used on every page with large files, as the file function reads the entire file, and if it has to be done many times it will slow down your system..


  •  

    Posting Permissions

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