You are here: Re: remove specific line « PHP Language « IT news, forums, messages
Re: remove specific line

Posted by Kimmo Laine on 06/20/05 15:26

"Ron Eggler @ work" <nospam@hotmail.com> wrote in message
news:3hnjj9Fhg183U1@individual.net...
> Ron Eggler @ work wrote:
>> [snip]
>>> If it still doesn't
>>> work, I don't know what will...
>>
>> oh very bad because it doesn't work...: :( I pasted the Code below....
>>>
>>> This from the manual, the chaper about variable scope: "In PHP global
>>> variables must be declared global inside a function if they are going
>>> to be used in that function."
>>
>> yup, and the code looks like this:
>> [Code]
>> //at the top of the file:
>> $blacklist="blacklist.txt";
>>
> //--------------------------------------------------------------------------
>> ----
>> function removeEMail($email_address)
>> {
>> global $blacklist;
>> // Read the file into an array. One address per row
>> $emails = file($blacklist);
>> // Remove given email address
>> unset($emails[array_search($email_address,$emails)]);
>> // Change array back to end-of-line separated string, write to file
>> if(@$handler = fopen($blacklist,"w"))
>> {
>> foreach($emails as $line)
>> fputs($handler, "$line\n", 512);
>> fclose($handler);
>> }
>> echo $email_address." removed from ". $blacklist ."<br>\n";
>> }
>> [/Code]
>
> oh now I see when writing the array back to file it adds about 16 empty
> returns between every address... :( why that?
>


Stupid me. I didn't remember that file() leaves the end of lines in the
strings, so adding them is unnecessary.

Change fputs($handler, "$line\n", 512);
to -> fputs($handler, "$line", 512);

Maybe now...

I should rtfm... It says right there: "Each element of the array corresponds
to a line in the file, *with the newline still attached*".

Because of this, each time you saved the file, it doubled the lines... Thus
one line and 15 empty lines...

--
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]


Удаленная работа для программистов  •  Как заработать на 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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация