few days ago a nice chap named sneakyimp helped me create a peice of code for a chat script im coding , im still pretty new to php. I tried posting in our original thread but noticed after it was marked as resolved, so sneaky if youre out there.. or anyone for that matter that can help me... im gonna post my reply that i just left in the other thread here and if anyone knows how to fix 'er up please shed some light and id be much appreciative! i will provide a link here to the original thread as well in case any of you can help.
http://www.phpbuilder.com/board/showthread.php?t=10365204
BELOW THIS LINE IS THE NEW PROBLEM I HAVE AND / OR NEED HELP RESOLVING!!
hey sneakyimp (or anyone). question following up on this here.
i've managed to get everything working perfectly as described above. but, i did find one undesired side effect.
when i do a single word string in the input field lets say for example
/quit
it doesnt recognize it (maybe the code you gave me was reliant upon more than one word being in the string?) not sure as im still analyzing it and figuring out how the code works.
is there anyway to slightly modify it so that it still works exactly as functioning now, except for it to stop and recognize if there is only one word posted?
most of my commands (90% or more) will require secondary input so is not much of a problem. but there will be 3 or 4 commands (such as /quit) where there is nothing following the string like /kick ChatUser Reason.
Below is the code as I have it setup.
$pattern = '#/(\w+)\s+(.+)$#'; // this is for the /command interface in the main script
if (preg_match($pattern, $mes, $matches)) {
$cmd = $matches[1];
$args = preg_split('/\s+/', $matches[2], -1, PREG_SPLIT_NO_EMPTY); // this should split the remainder of the string after the command along white space
$cmd_file = "$root/chat/bin/cmd/" . $cmd . '.php'; // the command handler
$user = array_shift($args);
$everything_else = implode(' ', $args);
if (file_exists($cmd_file)) {
include $cmd_file;
exit();
} else {
$cmderror = "*** The command $matches[0] is not recognized";
$mes = "";
}}
much appreciated in advance