Php 将该字符串置于另一个字符串的右侧
我一直在我的聊天/聊天箱上工作,我的Php 将该字符串置于另一个字符串的右侧,php,strpos,Php,Strpos,我一直在我的聊天/聊天箱上工作,我的用户表中有一行名为静音(0表示未静音,1表示静音)。我想做的是,当你输入!静音应使用更新行,并将静音设置为1 我知道如何检查字符串是否包含!静音,如下所示: if (strpos($sboxmsg,'!mute') !== false) { } 问题是,我不知道如何让事情变得正确!沉默。我还需要将所有内容向右转换为一个变量,以便稍后在查询中使用 例如: !mute Nick 然后它将尼克存储在一个名为eg.$variable1 这可能吗?感谢您的帮助 使
用户
表中有一行名为静音
(0表示未静音,1表示静音)。我想做的是,当你输入!静音
应使用
更新行,并将静音设置为1
我知道如何检查字符串是否包含!静音,如下所示:
if (strpos($sboxmsg,'!mute') !== false) {
}
问题是,我不知道如何让事情变得正确!沉默。我还需要将所有内容向右转换为一个变量,以便稍后在查询中使用
例如:
!mute Nick
然后它将尼克存储在一个名为eg.$variable1
这可能吗?感谢您的帮助 使用
$variable1 = preg_replace('/^\!mute\s+/', '', $whatever_input);
使用
使用
使用
你可能会在
上爆炸!静音
:
$pieces = explode($sboxmsg, '!mute ');
$muted = (count($pieces) > 1);
if ($muted) {
$muted_user = $pieces[1];
}
你可能会在
上爆炸!静音
:
$pieces = explode($sboxmsg, '!mute ');
$muted = (count($pieces) > 1);
if ($muted) {
$muted_user = $pieces[1];
}
你可能会在
上爆炸!静音
:
$pieces = explode($sboxmsg, '!mute ');
$muted = (count($pieces) > 1);
if ($muted) {
$muted_user = $pieces[1];
}
你可能会在
上爆炸!静音
:
$pieces = explode($sboxmsg, '!mute ');
$muted = (count($pieces) > 1);
if ($muted) {
$muted_user = $pieces[1];
}
是的,你可以像这样拿你想要的那部分绳子
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
中有了Nick是的,您可以像这样获取字符串的一部分
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'.
}
if (strpos($sboxmsg,'!mute') !== false) {
$pieces = explode('!mute ', $sboxmsg);
if (count($pieces) > 1) {
$muted_user = $pieces[1];
$muted_value = 1
}
}
现在您在
$mutedName
中有了Nick是的,您可以像这样获取字符串的一部分
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'.
}
if (strpos($sboxmsg,'!mute') !== false) {
$pieces = explode('!mute ', $sboxmsg);
if (count($pieces) > 1) {
$muted_user = $pieces[1];
$muted_value = 1
}
}
现在您在
$mutedName
中有了Nick是的,您可以像这样获取字符串的一部分
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'.
}
if (strpos($sboxmsg,'!mute') !== false) {
$pieces = explode('!mute ', $sboxmsg);
if (count($pieces) > 1) {
$muted_user = $pieces[1];
$muted_value = 1
}
}
现在你在
$mutedName
中,Nick得到空间的位置,然后substr()
所有在右边的东西,给你名字得到空间的位置,然后substr()
所有在右边的东西,给你名字得到空间的位置,然后substr()
所有在右边的东西,为您命名获取空间的位置,然后substr()
将所有内容放在该位置的右侧,为您命名为最简单的解决方案。谢谢,工作顺利!当我可以的时候,我会把这个标记为最好的答案。似乎是最简单的解决方案。谢谢,工作顺利!当我可以的时候,我会把这个标记为最好的答案。似乎是最简单的解决方案。谢谢,工作顺利!当我可以的时候,我会把这个标记为最好的答案。似乎是最简单的解决方案。谢谢,工作顺利!我会在可能的时候把这个标记为最佳答案。
if (strpos($sboxmsg,'!mute') !== false) {
$pieces = explode('!mute ', $sboxmsg);
if (count($pieces) > 1) {
$muted_user = $pieces[1];
$muted_value = 1
}
}