"Niels Bosboom" <n.bosboom@wanadoo.nl> wrote in message
news:jxgdb.358684$lA6.11687607@castor.casema.net.. .[color=blue]
> Hi!
>
> I am using PHP4.3.3 on a windows XP platform.
>
> I am building a small program that will allow my students to subscribe and
> unsubscribe from a service that will let them know when new results of[/color]
their[color=blue]
> exams are added to the webpage of school.
> Since I am not allowed to use mySQL as a database, I am using a simple[/color]
flat[color=blue]
> text-file to store the emailadresses submitted by my students.
> I can already add addresses to the file, even after I have checked if they
> already exist.
>
> But now I am working at the unsubscribe-part of the script, and I have
> simply no idea how to remove the string from the file.
> Anybody have any ideas? Please keep in mind that I am total newbie to PHP
> (although I am already a little proud to have achieved so much in so[/color]
little[color=blue]
> time without any help so far).
>
> The text-file looks like this:
>
a_name@domain.com,
>
another_student@anotherdomain.com
> etc
> But I can easily adjust the "write-email"-part of my script.
>
> TIA
>
> Niels Bosboom.
>
>
>[/color]
// UNTESTED!
// email to remove is in $_POST['email']
$filearray = file ( 'list.txt' );
$newarray = array();
foreach ($filearray as $email ){
if ( $email != $_POST['email'] )
array_push ( $newarray, $email );
}
$string = implode ( "\n", $newarray );
$fp = fopen ( 'new.txt', w );
fwrite ( $fp , $string );
fclose ( $fp );