I was wondering if it is possible to delete one line in a txt file using php.
I store emailadresses in a flat txt file named databse-email.txt
I use the code for this:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = $_POST['email-subscribe'] . ',' . "\n";
$store = file_put_contents('database-email.txt', $email, FILE_APPEND | LOCK_EX);
if($store === false) {
die('There was an error writing to this file');
}
else {
echo "$email successfully added!";
}
}
?>
the form:
<form action="" method="POST">
<input name="email-subscribe" type="text" />
<input type="submit" name="submit" value="Subscribe">
</form>
The contents of the file are as follows:
janny@live.nl,
francis@live.nl,
harry@hotmail.com,
olga@live.nl,
annelore@mail.ru,
igor@gmx.de,
natasha@hotmail.com,
janny.verlinden@gmail.com,
All lines are ,
split.
Say I want to delete only emails: igor@gmx.de
How can i do this?
What I want to achieve is a unsubscribe form and deleting one line in a file .txt
source
share