strpos问题为0 == false? [英] strpos issue with 0==false?

查看:170
本文介绍了strpos问题为0 == false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用strpos查找一个字符串在另一个字符串中的位置.我首先检查该字符串是否在其中找到.这是我的台词:

I'm using strpos to find the position of a string in another string. I first check if the string is found at all in there. Here's my line:

if (strpos($grafik['data'],$ss1)<>false && strpos($grafik['data'],$ss2)<>false && strpos($grafik['data'],$ss1) < strpos($grafik['data'],$ss2))

我检查两个字符串是否都包含,然后将第一个字符串放在第二个字符串之前.在php手册中,它说当找不到字符串时strpos返回false.但是,如果我的字符串从零位置开始(strpos从其开始就返回0),则该语句

I check if both strings are contained and then I want the first one to be placed before the second one. In the php manual it says that strpos returns false when string is not found. However if my string starts at the zero position (strpos returns 0 since its the beginning), it seems like this statement

strpos($grafik['data'],$ss1)<>false

是错误的.不知何故0 == false?当strpos返回0时,如何使语句为真?

is false. Somehow 0==false ? How do I make the statement true when strpos returns 0 ?

推荐答案

来自 http ://www.php.net/manual/zh/function.strpos.php :

警告

此函数可能返回布尔值 FALSE,但也可能会传回 非布尔值,其计算结果为 FALSE,例如0或".请阅读 有关布尔值 信息.使用 ===运算符 测试这个的返回值 功能.

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

您必须使用===运算符而不是==.

You have to use the === operator instead of ==.

在您的情况下,请使用!==而不是使用<>:

In your case, instead of using <>, use !==:

strpos($grafik['data'], $ss1) !== false

如果在$grafik['data']

这篇关于strpos问题为0 == false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆