Re: Sorry, really stupid question...
| From: | Phil Powell | Date: | Sat, 28 Dec 2002 20:39:50 +0000 |
| Subject: | Re: Sorry, really stupid question... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-129527@lists.php.net to get a copy of this message | ||
I checked, and I am adding just "bob". Turns out to be a wacky logic
problem.
nicknames.txt contains this:
phil\n
bob\n
When "bob" leaves the chatroom nicknames.txt becomes:
phil\n
BUT.. apparently that's not it either; the carriage return is also somehow
stripped out. So instead it's this:
phil
so when "joe" comes on board instead of
phil\n
joe\n
I get
philjoe\n
Understand? This is a complicated logic problem I can't figure out other
than doing this:
$stuff = fread($fileID, filesize("nicknames.txt", 100000));
if (strlen($stuff) > 0) $priorNickNewLine = "\n";
...
fputs($fileID, $priorNickNewLine . $nickname . "\n");
Phil
"David Rice" <davidrice@rogers.com> wrote in message
news:C1A2CB28-1A9E-11D7-B971-00050218CE10@rogers.com...
> Hi Phil:
> It probably does what you are asking it to do. Have you checked the
> value of $nickname to see if you are setting it to "bob" or appending
> "bob" to it?
> i.e first time $nickname = "phil"
> second time $nickname = "philbob"
>
> HTH
>
> David
> On Saturday, December 28, 2002, at 02:24 PM, Phil Powell wrote:
>
> > Honestly, what does this do:
> >
> > $fileID = fopen("nicknames.txt", "a") or die("Could not open
> > " . $path
> > . "/nicknames.txt");
> > chmod("nicknames.txt", 0755);
> > fputs($fileID, $nickname . "\n"); fflush($fileID); fclose($fileID);
> >
> > What does it EXACTLY do? What I'm trying to do is very very simple:
> > I have the nickname of "phil" and I add it to nicknames.txt as "phil"
> > + "\n". The next person adds his name as "bob" + "\n".
> > However, this
> > happens:
> >
> > phil
> > philbob
> >
> > Is it due to the way I'm adding to the file? Can someone show me how
> > to append to a file properly without carrying over persistent existing
> > data like what you see above, instead having it like this:
> >
> > phil
> > bob
> >
> > Thanx, I'm lost here.
> >
> > Phil
>