Delete from 'start' to 'end' of file

Hello i am new to php and i need some help.
I’m looking to delete a section of a php file (start - end) from another file with a submit button.

So lets say i have logdata.php and index.php.
The submit button would be in the index.php and on the logdata.php i could have:

Start
test text
test text
test text
test text
End

Everything in between would be deleted while still leaving Start and End.
Any kind of help would be appreciated.
Thank you

So, you want to edit a file? How big might it be. It is easy to read the file into a string, only a couple lines. And, then you can parse it and remove whatever and write it back out. Depends on how big it might be.

Thanks for the reply ErnieAlex,
The logdata.php file will have about 10 lines although they will ip address and date stamps.

Well, there are simple ways to read files into strings. It only takes about 4 lines of code.
Then, once stored in a string, you can parse it and pull whatever you would like out of it.
So, if the file is only a few lines, it will be very small. It would fit into a string without issues.

This code is how you read a file into a string:
[php]
$myFile = “pathtofile/filetoread.txt”;
$filehandle = fopen($myFile, ‘r’);
if (filesize($myFile) == 0){
die(“Empty data file!”);
}else{
$DataFile = fread($filehandle, filesize($myFile));
}
fclose($filehandle);
[/php]
I added a check for an empty file. This would be where you might change your display indicating this.
So, the $myFile is the pointer to wherever you have this file stored. The variable $DataFile can be called
anything, I just used this name. And, this routine will fill the variable with the text data from the file.

Then, you can use the string and search it and get the data you want. If you need further help with
that part, let us know…

Sponsor our Newsletter | Privacy Policy | Terms of Service