Re: select text from a text file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 5 Jan 2005 11:58:59 -0000, Ed <ed@xxxxxxxxxxxx> wrote:
> Happy new year folks!
> 
> The titlemight make this seem like an easy to answer question
> 
> However here's the complicated bit (well for me anyway).
> 
> In my text file that is written to by the users in a chatroom it looks like this:
> 
> nickname||color||what the user is saying||user
> 
> how can i make it so that if they have a private message when they press update it pulls the message from the text file and displays it in the frame but also deletes the text?
> 

You should be using a database for this, it makes things so much
easier.  That being said, here's one way to go about the text file
version:

Open the file, read through it line by line.
As you read it, push the lines into an array.
If you find a private message for the user, store that in a variable,
and do not push it into the array.
Finish reading the file.
If there's a private message, you've got it in a variable, and you can
overwrite the private message file with the array you've stored, which
is all of the current private messages minus the one you're about to
display.

Please note, this does not scale at all, especially in the fast-paced
world of chat rooms.  You will likely end up with file locking
problems if you proceed with the flat-file method.


> Also, how can i make it so that if in a drop down menu they select the word "everybody" it goes to a file called messages.txt and if they select "user" or "user2" or "user3" from the list it writes to private.txt is this at all possible? user and user2 etc arent hardcoded it's pulling the names from a list of online users.
> 

Are you talking about appending messages to a text file?  In that
case, you can have the dropdown submit with the message, and in the
PHP code have a case for 'everybody' where it writes to messages.txt,
and if it's not 'everybody', write it to private.txt with the username
that was selected from the dropdown as part of the row.

Does that answer your question?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux