加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP完全匹配字符串

发布时间:2020-12-13 18:13:38 所属栏目:PHP教程 来源:网络整理
导读:$check = 'this is a string 111';if ($check = 'this is a string') {echo 'perfect match';} else {echo 'it did not match up';} 但它每次都返回完美匹配,而不是它不匹配…我似乎无法得到字符串来匹配案例,它只会在字符串的一部分匹配时起作用. 如果我尝
$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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读