PHP 精确匹配一个字符串

标签 php string match

$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/

相关文章:

php - 适用于 PHP 的 Memcached 和故障转移

php - Laravel 重命名文件

php - 如何显示当前有多少用户在线

php - 什么是 netbeans 中的重要文件文件夹项目

perl - 如何在字符串中插入 Perl 哈希元素?

c - 如何在 C 中打印定义的字符串宏?

.net - 在C#Web服务中处理UTF-8字符串

SQL 查找在两个表之间匹配的大多数行

检查整个多行 HTML header 时 HTML 状态代码的 Java 正则表达式

javascript - 如果一组不匹配,.match() 返回 null