$check = 'this is a string 111';
if ($check = 'this is a string') {
echo 'perfect match';
} else {
echo 'it did not match up';
}
但它每次都返回完美匹配而不是不匹配...我似乎无法让字符串完全匹配大小写它只有在部分字符串匹配时才有效。
如果我尝试使用板代码和正则表达式模式使事情复杂化,那将成为一场噩梦。
if ($check = '/\[quote(.*?)\](.*?)\[\/quote\]/su') {
$spam['spam'] = true;
$spam['error'] .= 'Spam post quote.<br />';
}
因此,如果帖子仅包含引号标签,它将被视为垃圾邮件并被丢弃,但我似乎无法解决它,也许我的模式是错误的。
最佳答案
你需要使用 ==
而不仅仅是 =
$check = 'this is a string 111';
if ($check == 'this is a string') {
echo 'perfect match';
} else {
echo 'it did not match up';
}
=
将分配变量。
==
将进行松散比较
===
会做严格比较
参见 comparison operators获取更多信息。
关于PHP 精确匹配一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8943372/