Results 1 to 3 of 3

Thread: deleting the first line of a text file with php

  1. #1
    Join Date
    Aug 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default deleting the first line of a text file with php

    how is it done?

  2. #2
    Join Date
    Dec 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    just type in the text file like this:
    (im assuming you know that // means comment)

    PHP Code:
    <?php
    $array 
    file('text.txt'); // Takes the file, and puts it in an array each seperated
    // by line.
    $array[0] = ""// Deleted the first line, $array[1] is second line... etc.
    foreach($array as $val){ // Put the array into a loop, and displayed every line.
    echo $val."<br />"// Echo the line, then line break
    // close our loop
    ?>
    This only replaces the first line with a blank text, however it is not permanent, if you want to actually remove it and SAVE the file with the first line deleted, then you need to fwrite() or fputs() it.

  3. #3
    Join Date
    Aug 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    that's great, cheers!

Bookmarks

Posting Permissions

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