In SQL we have NOT LIKE %string%

在SQL中我们没有像%string%

i need to do this in PHP.

我需要在PHP中执行此操作。

if ($string NOT LIKE %word%) { do something }

if($ string NOT LIKE%word%){做某事}

i think that can be done with strpos()

我认为可以用strpos()完成

but couldnt figure out how..

但无法弄清楚如何......

i need exactly that comparission sentence in valid PHP.

我需要在有效的PHP中完全相同的comparission句子。

if ($string NOT LIKE %word%) { do something }

if($ string NOT LIKE%word%){做某事}

Thanks

谢谢

4 个解决方案

#1


54

if (strpos($string, $word) === FALSE) {
   ... not found ...
}

Note that strpos() is case sensitive, if you want a case-insensitive search, use stripos() instead.

请注意,strpos()区分大小写,如果您想要不区分大小写的搜索,请使用stripos()。

Also note the ===, forcing a strict equality test. strpos CAN return a valid 0 if the 'needle' string is at the start of the 'haystack'. By forcing a check for an actual boolean false (aka 0), you eliminate that false positive.

还要注意===,强制进行严格的相等测试。 strpos如果'needle'字符串位于'haystack'的开头,则返回有效0。通过强制检查实际的布尔值false(也就是0),可以消除误报。

更多相关文章

  1. 几个有用的php字符串过滤,转换函数代码
  2. PHP - 将字符串转换为键值数组
  3. 使用mod_rewrite将文件夹转换为查询字符串
  4. 计算字符串的MD5哈希值
  5. 有一种防弹的方法可以检测php字符串中的base64编码吗?
  6. 如何在mysql中配置区分大小写的数据库标识符
  7. 在两个不同的地方分割/爆炸一个PHP字符串
  8. PHP中的嵌套(多个)字符串插值
  9. 查找具有特定数据字符串的数组并返回其具有的另一个数据字符串

随机推荐

  1. 如何减去两个日期和时间来得到不同?
  2. 使用包含特定号码的网址重定向到索引
  3. wampserver的虚拟主机的配置
  4. php下删除一篇文章生成的多个静态页面
  5. THINKPHP 中关联查询(多表查询)
  6. 使用phpstorm进行PHP断点调试
  7. centos上安装php运行环境
  8. 招聘php开发工程师3-5人
  9. HPH+Mysql注入点利用 读取文件内容和导出
  10. 如何只从$_SERVER['HTTP_REFERER']中选择