CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    73

    Remove last line in a file PHP/Store all lines except the last one

    Hello all! Is there a way to remove the last line in a text file? Or, alternatively, is there a way to read a text file until the penultimate line of the file?
    That is, if you have a file like:
    Code:
    AAAA
    BBBB
    CCCC
    DDDD
    XXXXXXXX
    read all lines except the last one? In the previous example I need to hold only AAAA, BBBB , CCCC and DDDD.
    Thank you!

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Remove last line in a file PHP/Store all lines except the last one

    Use PHP's file() method which will return an array of the lines. Read through using a for() loop and leave off the last iteration.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

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

Featured