Removing a line of text by a keyword search using php

Hello I am trying to make a guestbook, so far I am doing good but I need to make a button that will allow me to remove a guest(“entry”) from the guest book I was going to try doing it by creating a form that asked the user to enter in either the email or first name of the entry ( they are stored in the text file as"firstname [email protected]) I am not quite sure how to do this could someone please help me out!

Well, is this for a class project? Seldom do programmers use text files for something like a guestbook.
Normally, you would set it up in a database and then to remove an entry, you would just use a query
to delete the needed record. Handling this in a text file is tricky.

To accomplish this using a text file, you would have to know the record you are looking for.
If you had a list of buttons, one for each guest, you could save the value of the line of data you need to
look for in the value for that button. Next, you could read the entire file into a variable and remove that
entry from the variable with the string-replace function. Then, rewrite the file back out. But, once the file
becomes large, this would not work well. Once it is a large file, you would have to read the file one line
at a time until you find the record you need to delete and and skip it all the while writing the records out
to a second file. Then, delete the first file and rename the new file. Complicated and lots of work for
a task which is much much easier to do with a database system.

So, you have a few ideas to start with. What is the reason you need to do it with text files instead of
the correct way of using a database? I bet it is for school? Correct? LOL, either way, you some food for
thought to start with… Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service