Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i'm trying to make a chat room script it's almost done but right now i'm making some irc commands. how can i make it so thhat if someone types /me blah then it will display something else?
 
You could use regular expressions to do pattern matching and string replacement. I am assuming that you'd want to replace "/me" with the user's name?

Try this:
Code:
//Example 1
// replace ALL instances of "/me"
$message = preg_replace("/\/me/", $user_name, $message);

//Example 2
// replace only instances at the beginning of the string
$message = preg_replace("/^\/me/", $user_name, $message);

//Example 3
// replace case variations, i.e. "/Me", "/ME", & "/mE"
$message = preg_replace("/^\/me/i", $user_name, $message);

Read Here:

Enjoy! :-D
 
Not exactly. If someone types:

/me falls down

Then I want it to make it into:

[$Time] $Username falls down
 
If you could give us the code relevant to this, it would be a lot easier helping you. //Daniel
 
Forgive me, Aren't chat room scripts real time and therefore unable to be run effectively as they require constant updates?

PHP is server side so you'd have to keep refreshing your browser window.

Normally this sort of thing would be done in java. ***************************************
Party on, dudes!
[cannon]
 
Well, just use the line of code that behaves as you want (I'd recommend #3, but I listed the others as examples), and replace:
Code:
$user_name
- with -
Code:
"[".$Time."] ".$Username

Did you look over the manual pages I listed? They'll be great help. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top