Just put the function's code from the "php-delete-line-in-file.php" file in yours and call the function like this:
deleteLineInFile("myFile.ext","myString");
- read the file line per line
- store each line in an array
This way the file is backed up so it can be opened for writing, erasing all the data
- for each line stored in the array, if it doesn't contain the string we write it back in the file
- else we do nothing so only the lines not containing the string are written back
I had a CSV file who looked like this:
text1;text2
text3;text4
text5;text6
And I needed to remove the line containing the "text3" string. I did my function so it can work with my specific file, and then I changed it to work with any kind of file (tested with CSV, TXT and HTML files).
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 1, August 2012
Yann Jajkiewicz <contact@yann.me>
Everyone is permitted to copy and distribute verbatim or modified
copies of this program.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.