How do I open a file and overwrite contents?

nlester

New Member
Messages
10
Reaction score
0
Points
0
Hello,

I'm working in PHP. I have a semicolon-delimited file that contains information of the users for my site (first name, last name, email address, etc.). I want to give users the opportunity to update their information. I have figured out how to read this file (opening the file, reading line by line, and using the explode function to parse out the variables), and I know how to append new users to the end of the file. But what I don't know how to do is to open it and change just one variable. Any advice would be appreciated.

NAL
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
You will go mad trying to manipulate user information without a database. Also, the slightest error could delete your information. But, you could use the strpos() function to find the user information and then use the str_replace() function to change it.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Or you could try reading line by line, storing each line in an array and then look for the index that has to be chaged, change the contents of that index and finally write the array down again.
But as Twinkie says, you'll go mad in no time. Use databases!
 

tnl2k7

Banned
Messages
3,131
Reaction score
0
Points
0
Hello there,

A database really would be your best option here. Believe me, I run an administration panel on my games arcade and it's a flipping nightmare trying to change password with a flat-file backend.

I switched to using a MySQL database table to store everything and much prefer it. I'd advise you to do the same thing. I've found it so much better that I've since ported my advertising system to it and made the system that stores the names and locations of game files work using MySQL too.

-Luke.
 

cursedpsp

New Member
Messages
237
Reaction score
0
Points
0
wouldn't fopen($filename, "w+"); work?

You open the file then delete the content?
 
Top