Reply to Re: remove specific line

Your name:

Reply:


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

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация