Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Dec 2003
    Posts
    2
    Member #
    4130
    Hi,
    I'm new to PHP. I have a question about writing/changing the file in php.

    I created a text file to store users' information. I use fwrite to create the text file.

    In my next program, I allow users to change their information. After users submitted the information, I compare it with my text file.

    Here's the snippet of my code:
    //first I open the my text file
    $file_var = fopen("userdata.txt","r+") or
    die ("Error - userdata.txt cannot be opened");
    //then I read the file
    while (!feof($file_var)){
    $line = fgets($file_var, 150);
    list ($username,$fname,$lname) = split (":", $line,3);
    $currentusername = $username
    if ($login == $currentusername){
    .
    .
    .
    }
    Question: If the login name is in the file, what command should I use so I can write the users' information into the same line in the text file??

    Any suggestion??

    Thanks.

    PHPnewbie

  2.  

  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Obviously, using a database would make this quite easy.

    If you store data in a flat file (i.e. a text file), it will become less flexible and get slower (with regard to prcessing) as it grows in size.

    I've never tried this myself, but you could maybe use a string replace command (for example ereg_replace) to alter the content before closing the file again.

    Some info about that function here

    Not sure if that's the proper approach though. I'm on a bit wobbly turf here.
    S. Rosland

  4. #3
    Junior Member
    Join Date
    Dec 2003
    Posts
    2
    Member #
    4130
    Thanks.
    I'm using a text file because this is part of my Web development class project. We haven't been taught on using the database yet.

    I'll try your suggestion and let you know if it works or not.

    Thanks again for the reply.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:32 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com