0

Hi!

I have txt file containing something like:
User1
123434
User2
435345
User3
234234
User3
234924

Now, i need to delete one user from that txt file, along with number that is after the user
so lets say that i entered in delete form: User1 , then i would like my txt file look like:
User2
435345
User3
234234
User3
234324

I tried with deleting it by lines (delete line 1, then delete line 2, but it really didnt work properly, also i tried with str_replace($Data,"",$Handle); but didnt work at all). I want to make a form, in which i would enter the username, and press deleteor some button, and the user along with his number would get deleted (i already made aform, but i cant figure out the function)
So if aynone has an idea how i could achieve this, i would be very thankfull if they share it

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by chrishea
0

I'm not going to write the code for you but it seems pretty straightforward:

Open the input file (fopen)
Open an output file
Read a record (fgets)
compare specified user name with the record content
if it's equal
skip it
read the next record and skip that too
else
write the record to the output file

loop through the input file until EOF
Close the files
rename the input file
rename the output file to the original input file name
delete the original input file or move it to an archive

You're done

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.