Forum Moderators: coopster

Message Too Old, No Replies

IRC commands --- command + random text

         

Gero_Master

2:52 pm on Mar 18, 2006 (gmt 0)

10+ Year Member



Hello!

I'm making AJAX/PHP/MYSQL chat thing, and I need to add some IRC commands.

Unfortunately, I don't know how to make it ask:

IF $_POST['message']

is something like --> /kick *

that * refers to persons name. But I need to know how to make it notice which command is used and seperate the actual commad from the command tag.

Like if I write "/time 60" it would do the function i have arraged for this "/time" command. And it would use that "60" part as a variable in that function...

Thats pretty hard to understand, but I hope someone will get the idea I'm trying to expres :)

coopster

8:15 pm on Mar 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could use regular expressions to find and grab things in the supplied input string. See the PHP manual pages on Perl Compatible Regular Expressions [php.net] for more information.

Anyango

6:20 am on Mar 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If all your commands, infact "actual command"(s) will be single word and wont contain any spaces then u could prolly split that

$_POST['message']

on white space, first thing would be your command and rest would be parameter(s)

like

$_POST['message']= "/kick Anyango"

if you split that word on space

you ll get

command=/kick
parameter=Anyango

not sure if it helps

Gero_Master

7:57 am on Mar 20, 2006 (gmt 0)

10+ Year Member



Thanks for both of you for your replies!

The splitting thing does help me to get the idea, but I have learned PHP so reacently that I don't know how to do that yet.

I'll try to look for some splitting tutorials :)

Anyango

8:18 am on Mar 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



glad it helped. spliting is as easy as eating chocolate ;)

$commandArray=split(" ",$_POST['message']);

$command=$commandArray[0];
$parameter=$commandArray[1];

now u can use those variables anywhere u want

[php.net...]

omoutop

9:45 am on Mar 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If your commands contain text with spaces, use str_replace instead. That way u can nullify the command and all that its left is the actual paramaeters:
example:

$text = "/kick ban some_poor_soul"

$new_text = str_replace("/kick ban ","",$text);
which leaves you with $new_text = "some_poor_soul";

Gero_Master

5:03 pm on Mar 20, 2006 (gmt 0)

10+ Year Member



Thanks... Now it's up to testing!

For the last reply:
That is also usable, but it would make the regocnition of the actual command hard. There will be numerous commands like: name_color, msg_font etc...

So thats why I'm gonna go with the splitting this time :)

Thanks for all of ya!