Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Bernz's Avatar
    Junior Member

    Status
    Offline
    Join Date
    May 2009
    Posts
    6
    Downloads
    0
    Uploads
    0
    Yes, you can do it, but you'll need data manipulation (no function does this natively).

    If the file is relatively small (< 1 Mb), you can:

    - load the entire file into memory (use the file_get_contents() function),
    - add the new row at the line you want
    - delete the initial file (unlink() function)
    - create a new file with the same name (file_put_contents() function)

    Good luck!

  2. #2
    Ben B's Avatar
    Member

    Status
    Offline
    Join Date
    May 2009
    Posts
    57
    Downloads
    0
    Uploads
    0

    PHP file write, add to a file instead of overwrite?

    Is it possible?

    I am trying to write to a file that already has content in it. Lets say I have file.txt:

    ------------------------------
    First line
    second line
    last line
    ----------------------------------

    so what if i want to just add something between "second line" and "last line"? Is this at all possible? How can I do this with PHP?

    Thanks in advance.

 

 

Quick Reply Quick Reply

Click here to log in


What is the sum of 36 and 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 11-24-2010, 04:32 AM
  2. Replies: 0
    Last Post: 09-20-2009, 01:35 PM
  3. Replies: 0
    Last Post: 05-14-2009, 02:02 PM
  4. Replies: 0
    Last Post: 04-20-2009, 01:19 PM
  5. PHP flat file overwrite line? Is it possible?
    By Php N in forum Discuss PHP
    Replies: 0
    Last Post: 12-02-2008, 03:51 AM

Bookmarks

Posting Permissions

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