2015-10-27 74 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 

        } 
      } 
相關問題