|
Posted by Kimmo Laine on 06/17/05 16:43
"Ron Eggler @ work" <nospam@hotmail.com> wrote in message
news:3hg0mlFh1hjoU1@individual.net...
> Kimmo Laine wrote:
>> "Ron Eggler @ work" <nospam@hotmail.com> kirjoitti
>> viestissδ:3hcgm7Fga8fmU1@individual.net...
>>> Hi,
>>>
>>> I got a textfile with e-mail addresses on every line. now I want to
>>> be able
>>> to delete one e-mail-address from this file and shift everything
>>> below one line up. how do I do that?
>>> Thank you! :)
>>
>> <?php
>> // Read the file into an array. One address per row
>> $emails = file("emails.txt");
>> // Remove given email address
>> unset($emails[array_search($email_address)]);
>> // Change array back to end-of-line separated string, write to file
>> file_put_contents("emails.txt", implode("\r\n", $emails));
>> // In, out, wipe the tool, say "thank you", and leave. Simple and
>> easy.
>
> Oh thank you very much! :)
> But I get these Messages:
>
> Warning: Wrong parameter count for array_search() in
> /srv/www/htdocs/web2/html/php/nospam/pop.php on line 31
Sorry, my mistake... replace
unset($emails[array_search($email_address)]);
with
unset($emails[array_search($email_address, $emails)]);
> Fatal error: Call to undefined function: file_put_contents() in
> /srv/www/htdocs/web2/html/php/nospam/pop.php on line 33
Hmm file_put_contents is fairly new function, available since PHP5. It is
seems that you're running the script with older php. Doesn't matter, that's
just a shortcut for:
if(@$handler = fopen("emails.txt","w")){
foreach($emails as $line) fputs($handler, "$line\r\n", 512);
fclose($handler);
}
--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com
Navigation:
[Reply to this message]
|