首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >strpos/stripos (严格比较)失败

strpos/stripos (严格比较)失败
EN

Stack Overflow用户
提问于 2017-08-28 22:50:32
回答 1查看 418关注 0票数 2

我现在有下面的strpos/stripos (尝试过,不改变结果),用于标记论坛帖子中的某些针头。

代码语言:javascript
复制
if (stripos($row->message, (string)$commit) !== false) {
  // Do stuff
}

然而,在少数情况下,当haystack ($row->message)包含针( $commit ) (使用强制转换,因为$commit可以是int)时,这些东西通常都很好用,而strpos/stripos则返回false。

例如:

代码语言:javascript
复制
$test = stripos($row->message, (string)$commit);

一个不起作用的场景的例子是:

代码语言:javascript
复制
// (string)$commit 
string(7) "818df50"
// $row->message
string(321) "Intro. Crashes as soon as the main menu is shown. Graphics are horribly broken, no fixes have been found as of yet. [attachment=194] Build Used: Pull Request #3333 (0.0.3-5929) -> RPCS3-v0.0.3-2017-08-27-818f50b Side note: States it can display at 1080p, yet it is boxed in 1080p. However, it is fine in 720p."
// $test (strpos/stripos) 
bool(false)

工作场景的一个例子是:

代码语言:javascript
复制
// (string)$commit
string(7) "2570911" 
// $row->message
string(219) "RPCS3 v0.0.3-3-2570911 Alpha The game doesn't even show its graphics window. [quote] ·F 0:00:34.138812 {PPU[0x1000000] Thread (main_thread) [0x0087c094]} MEM: Access violation writing location 0xcffff2d0 [/quote]" int(15) [2570911]
// $test (strpos/stripos)
int(15) [2570911]

我不知道我是不是错过了一些很明显的东西,我检查了几次,方法似乎是正确的。

注意:我知道有很多种方法可以这样做,但是在这个特定的场景中,我需要这些字符串比较。

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-28 23:04:00

以你为例..。

代码语言:javascript
复制
// (string)$commit 
string(7) "818df50"
// $row->message
string(321) "Intro. Crashes as soon as the main menu is shown. Graphics are horribly broken, no fixes have been found as of yet. [attachment=194] Build Used: Pull Request #3333 (0.0.3-5929) -> RPCS3-v0.0.3-2017-08-27-818f50b Side note: States it can display at 1080p, yet it is boxed in 1080p. However, it is fine in 720p."
// $test (strpos/stripos) 
bool(false)

针头818df50不包含在干草堆中。干草堆包含一个非常接近的字符串(818f50),但这并不完全匹配。

所以..。它在做正确的操作。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45928378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档