获取另一个字符串右侧的字符串

时间:2015-10-27 17:56:45

标签: php strpos

在我的聊天/ shoutbox上工作了一下,我的users表中有一行名为muted(0表示未静音,1表示静音)。我想要做的是,当您输入!mute <target>时,它应该使用<target>更新行并将muted设置为1.

我知道如何检查字符串是否包含!mute,如下所示:

if (strpos($sboxmsg,'!mute') !== false) {

}

事情是,我不知道如何获得任何权利!mute。而且我还需要将所有内容都转到一个变量中,以后我可以在查询中使用它。

示例:

!mute Nick

然后它会将Nick存储在一个名为eg的变量中。 $variable1

这可能吗?感谢所有帮助!

4 个答案:

答案 0 :(得分:2)

使用

$variable1 = preg_replace('/^\!mute\s+/', '', $whatever_input);

答案 1 :(得分:1)

您可以在!mute上爆炸:

$pieces = explode($sboxmsg, '!mute ');
$muted = (count($pieces) > 1);
if ($muted) {
    $muted_user = $pieces[1];
}

答案 2 :(得分:0)

是的,您可以像这样使用您想要的字符串部分。

widget.Toolbar

现在你有if (strpos($sboxmsg,'!mute') !== false) { $index = strpos($sboxmsg,'!mute'); //In index we save the start of '!mute'. $index = $index + 6; //Now we go to the end of '!mute '. Please note that here I also take the blank space. $mutedName = substr($sboxmsg, $index, strlen($sboxmsg) - $index); //We take from the original string, starting after '!mute'. } ,尼克

答案 3 :(得分:0)

position:relative;top:-40px;