如何在php中查找字符串的第二个空格? $string=“/kick(time)”//时间是可选的,用户是必需的 如果(!strpos($string,,)){ $firstSpace=strlen($string); }否则{ $firstSpace=strpos($string',); }

如何在php中查找字符串的第二个空格? $string=“/kick(time)”//时间是可选的,用户是必需的 如果(!strpos($string,,)){ $firstSpace=strlen($string); }否则{ $firstSpace=strpos($string',); },php,Php,我正在设计一个AJAX实时支持聊天室。使用/command我可以做一些事情,比如禁止用户、显示帮助等,但我不能因为问题而踢用户 为了得到,我使用下面的公式来查找第一个空格。 如何使用php使用strpos获得?您可以使用函数: $string = "/kick <user> (time)"; //time is optional, user is required if (!strpos($string, ' ')) { $firstSpace = strlen($strin

我正在设计一个AJAX实时支持聊天室。使用
/command
我可以做一些事情,比如禁止用户、显示帮助等,但我不能因为问题而踢用户

为了得到
,我使用下面的公式来查找第一个空格。
如何使用php使用strpos获得

您可以使用函数:

$string = "/kick <user> (time)"; //time is optional, user is required
if (!strpos($string, ' ')) {
    $firstSpace = strlen($string);
} else {
    $firstSpace = strpos($string, ' ');
}
$string=“/kick(time)”//因为是强制性的,而(时间)是可选的
$pieces=分解(“,$string);
echo$pieces[0];//踢
echo$pieces[1];//
echo$件[2];//(时间)
您可以使用以下功能:

$string = "/kick <user> (time)"; //time is optional, user is required
if (!strpos($string, ' ')) {
    $firstSpace = strlen($string);
} else {
    $firstSpace = strpos($string, ' ');
}
$string=“/kick(time)”//因为是强制性的,而(时间)是可选的
$pieces=分解(“,$string);
echo$pieces[0];//踢
echo$pieces[1];//
echo$件[2];//(时间)
使用偏移参数:

$string = "/kick <user> (time)"; //because <user> is mandatory whereas (time) is optional
$pieces = explode(" ", $string);
echo $pieces[0]; // kick
echo $pieces[1]; // <user>
echo $pieces[2]; // (time)
使用偏移参数:

$string = "/kick <user> (time)"; //because <user> is mandatory whereas (time) is optional
$pieces = explode(" ", $string);
echo $pieces[0]; // kick
echo $pieces[1]; // <user>
echo $pieces[2]; // (time)