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

Still need help with this...

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.