2015-10-27 76 views
0

在我的聊天/吼吼箱上工作了一下,我的users表中有一行叫做muted(0表示未静音,1表示静音)。我想要做的是,当你键入!mute <target>它应与<target>更新行,并设置静音为1获取另一个字符串右侧的字符串

我知道如何检查是否字符串包含静音,它是这样的:

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

} 

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

实施例:

!mute Nick 

然后将存储尼克在名为例如变量。 $variable1

这可能吗?所有帮助表示赞赏!

+0

得到空间的POS机,然后'SUBSTR()'一切的,正确的,给你的名字 –

回答

2

使用

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

似乎是最简单的解决方案。谢谢,它工作顺利!如果可以的话,将这个标记为最佳答案。 –

1

你可能会爆炸的!mute

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

是的,你可以把你想要这样的字符串的一部分。

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'. 
} 

现在,你必须在$mutedName,尼克

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

       $pieces = explode('!mute ', $sboxmsg); 

        if (count($pieces) > 1) { 

        $muted_user = $pieces[1]; 
         $muted_value = 1 

        } 
      } 
相关问题