#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Aurora, CO USA
    Posts
    4
    Rep Power
    0
    Is there a way to delete only specific items in a file. For example can I remove only one line from either the top bottom or middle of a file? I would basically like to be able to edit a file without having to regenerate it everysingle time. So I would like to be able to remove a line and then replace it with other information.

    TIA
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,646
    Rep Power
    4492
    Sure it's possible. When you read in a file, it's placed in a variable. You can put the whole file into one variable, or put each line into an array. Then you can do whatever you would do with a normal string. Search through it for the line you want to take out, use regular expressions to change things around, etc... When you're done, you write the variable or array back out and re-create the file.

    The PHP manual shows you how to read and write files.

    ---John Holmes...


    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Aurora, CO USA
    Posts
    4
    Rep Power
    0
    I understand the editing of the actual information, but the only way that I can find to write to a file, fputs(), and it doesn't seem to replace information it seems to just add it on top of the other information, or it appends it to the end of the file depending on what I tell it to do. Is there a way to clear a file, or write over the file, or how would I recreate the file?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    45
    Rep Power
    15
    http://www.php.net/manual/function.fopen.php

    (Quoting from that page)
    "'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. "

Similar Threads

  1. Pointer problem in opening a file
    By LAKI in forum C Programming
    Replies: 13
    Last Post: February 11th, 2004, 08:27 AM
  2. Pointer problems opening file *formatted*
    By LAKI in forum C Programming
    Replies: 4
    Last Post: February 11th, 2004, 06:06 AM
  3. PHP file upload script trouble
    By casbboy in forum PHP Development
    Replies: 9
    Last Post: February 5th, 2004, 07:42 PM
  4. Deleting a temporary internet file
    By Immortal1490 in forum HTML Programming
    Replies: 8
    Last Post: January 23rd, 2004, 09:56 PM
  5. Delete file from browser cache
    By CEO in forum Perl Programming
    Replies: 2
    Last Post: January 12th, 2004, 06:57 AM

IMN logo majestic logo threadwatch logo seochat tools logo