SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Vancouver, BC, Canada
    0 Post(s)
    0 Thread(s)

    How to *insert* data into a text database?

    I have a text database with the following format:
    unique_value1,string1,string2,string3, etc...
    unique_value2,string1,string2,string3, etc... 
    unique_value3,string1,string2,string3, etc...
    I would like to replace the second string with new information.. but I can't figure out how to do this. I know I should be using fseek to find the location of the string and then fput to insert it.. but I can't seem to figure out how they all work together.

    Can anyone help?
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Lawrence, Kansas
    0 Post(s)
    0 Thread(s)
    An easier way to do this is to use the file() function, which will read the ENTIRE text file into an array with each element of the array corresponding to a line in the file. You can then modify the array easily within PHP (i.e replace $arrayname[1] which is the element corresponding to the second line of the file with whatever you want it to be) and then stick the whole array back together into a single variable and over-write the original file with your new variable.


Posting Permissions

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