Re: remove a line from a text list
| From: | Chris Wesley | Date: | Wed, 05 Mar 2003 21:37:43 +0000 |
| Subject: | Re: remove a line from a text list | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138367@lists.php.net to get a copy of this message | ||
On Wed, 5 Mar 2003, Richard Kurth wrote:
> This script will remove a line from a text list of email address and
> then re-write the list. The only problem I am having is when it
> re-writes the list it adds a extra line between each record. How can I
> stop this from happening
Your code works as you'd expect ... on my mod_php 4.2.2 & Apache 1.3.26
setup. It's amazing though, because implode() is used incorrectly.
See below:
> $recordsarray = file($members);
> $remove = "rdkurth@northwesthost.com";
> $temp = array();
> for ($i=0;$i<count($recordsarray);$i++)
> {
> if (!strstr($recordsarray[$i], $remove))
> {
> $temp[] = $recordsarray[$i];
> }
> }
> $recordsarray = $temp;
> $lines = implode($recordsarray,'');
The above line:
I'm assuming you want to collapse $recordsarray into a sting, with the
elements of $recordsarray separated by a null char. Well, you told
implode() to collapse a null char into a string with the elements of null
char separated by $recordsarray ... inverted the arguments to implode().
I have no idea why an error isn't raised instead of kind-of working, but
anywho ....
Try switching the arguments around in the call to implode(), to:
$lines = implode('',$recordsarray);
http://www.php.net/manual/en/function.implode.php
If that doesn't correct the problem you're experiencing, let us know.
I have other ideas for you, but they may not be necessary if that solves
it.
HTH,
~Chris