0
我的AJAX聊天处理诸如命令:AJAX聊天命令/广播<text>命令?
/禁令名
/锁
多。
如果我使用一个以上的字,就像这样:
/广播大家好!
输出将是:
helloe
我的问题是: 我怎样才能使它不换(切)的文本,该命令后?
所以,当我使用这个命令:/广播你好大家,哈哈哈!
输出结果为:大家好,哈哈哈!
相反的:helloe
这是命令的方法:
public function handleCommands($message, $username)
{
// Splits the message.
$str = explode(' ', $message);
// Gets every space of the message, basically this is the command that comes after the slash
$command = substr(strrchr($str[0], '/'), 1);
/**
* If we have a value after the command:
**/
if (isset($str[1]))
{
$name = $str[1];
}
switch ($command)
{
case 'ban':
if(!empty($name))
{
if (ctype_alpha($name))
{
$this->ban($name, $username);
}
else
{
echo "Syntax Error. Do not use numbers or special characters.";
break;
}
}
else
{
echo "Syntax Error. usage: /ban (User name)";
break;
}
break;
case 'prune':
$this->prune($username);
break;
case '':
echo 'Available commands: /ban, /prune';
break;
case 'lock':
try
{
$this->lockChat($username);
}
catch (exception $r)
{
echo $r->getMessage();
}
break;
case 'broadcast':
echo $name;
break;
case 'unlock':
try
{
$this->unLockChat($username);
}
catch (exception $r)
{
echo $r->getMessage();
}
break;
default:
echo 'That command does not exist!';
break;
}
}
任何想法?
问题是位于此情况下:
case 'broadcast':
echo $name;
break;
警告:破灭()[function.implode]:用C传递参数无效:\ XAMPP \ htdocs中\聊天\包括\类\ Commands.class.php上行56 –
我做了一个小调整尝试新代码 – DevZer0
我收到了同样的错误。 –