我的 AJAX 聊天处理以下命令:
/禁止名称
/锁
和更多。
如果我使用多个单词,像这样:
/广播大家好!
输出将是:
你好
我的问题是:如何使它在命令之后不换行(剪切)文本?
所以当我使用这个命令时:/broadcast 大家好,哈哈哈!
输出将是:大家好,哈哈哈!
代替:你好
这是命令的方法:
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;