Results 1 to 4 of 4

Thread: Writing to a file. (PHP)

  1. #1
    Registered User
    Join Date
    Apr 2004
    Location
    EarthPlanet
    Posts
    2
    Thanks
    0
    Thanked
    0 times in 0 posts

    Writing to a file. (PHP)

    It's possible to ammend data within a file vs. just adding data to the beginning or the end of the file? Mean to change something in the "middle" of the file.

    Thanks.

  2. #2
    HEXUS webmaster Steve's Avatar
    Join Date
    Nov 2003
    Location
    Bristol
    Posts
    14,268
    Thanks
    286
    Thanked
    828 times in 468 posts
    • Steve's system
      • CPU:
      • Intel i3-350M 2.27GHz
      • Memory:
      • 8GiB Crucial DDR3
      • Storage:
      • 320GB HDD
      • Graphics card(s):
      • Intel HD3000
      • Operating System:
      • Ubuntu 11.10
    You can probably grep for the term you're looking for, obtain the line, then write to that line specifically, thus overwriting it. However, I've only ever used good old fwrite() so you'll have to check php.net for the right functions and statements - 'tis a great site though.
    PHP Code:
    $s = new signature();
    $s->sarcasm()->intellect()->font('Courier New')->display(); 

  3. #3
    ICY
    ICY is offline
    Registered+
    Join Date
    Oct 2003
    Posts
    15
    Thanks
    0
    Thanked
    0 times in 0 posts
    in my experience you can amend the data by reading the data into a variable
    eg.
    Code:
    $var = readfile($file);
    then you amend the data (i usually do it with forms so they are automaticaly filled and edited etc) and write it back into the file so the part you changed will be changed and the rest of the file will be consistent.

    eg.

    You want to change your username on a website. The file structure is like this

    ID|Name|Email|Password

    this allows you to split up the file into different segment with explode().
    You can then populate a form with these values by using the array in which explode has created (need a loop for lots of users find the right userid etc etc) so if the user changes a field in there preferences box, eg. Name becomes Jack then i set it so if the data is changed within the textbox the restructured file is sent on submission of the form and your username is changed.

    Seems well complicated if you dont get it, just ask a q..

  4. #4
    Member
    Join Date
    May 2004
    Posts
    50
    Thanks
    0
    Thanked
    0 times in 0 posts

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Passing variables, writing text files, etc
    By daverobev in forum Software
    Replies: 17
    Last Post: 03-12-2003, 03:49 PM
  2. windows 2000, corrupt file... help!
    By streetster in forum Software
    Replies: 4
    Last Post: 05-11-2003, 09:21 AM
  3. PHP and MySQL
    By Kezzer in forum Software
    Replies: 4
    Last Post: 28-10-2003, 02:59 PM
  4. Manage downloaded webpages file and folder
    By Zathras in forum Software
    Replies: 0
    Last Post: 17-09-2003, 05:37 PM
  5. Replies: 0
    Last Post: 20-08-2003, 11:42 AM

Posting Permissions

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