gpt4 book ai didi

PHP 精确匹配一个字符串

转载 作者:可可西里 更新时间:2023-11-01 12:43:56 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com