Find the answer to your Linux question:
Results 1 to 2 of 2
Does anyone have any suggestions on deleting a single line in a file using PHP? Thanks....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2004
    Posts
    61

    Deleting a Single Line in PHP


    Does anyone have any suggestions on deleting a single line in a file using PHP? Thanks.

  2. #2
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Sure, read file, delete line, write file back:

    Code:
    <?php
     $lines = file&#40;'path/to/file'&#41;;
      unset&#40;$lines&#91;$numberOfLine&#93;&#41;;
      $fp = fopen&#40;'path/to/file', 'w'&#41;;
      fwrite&#40;$fp, implode&#40;"\n",$lines&#41;&#41;;
      fclose&#40;$fp&#41;;
    ?>
    Since I don't have php currently installed I cannot guarantee that this code is 100% correct.
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

Posting Permissions

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