Strpos problem with 0 == false?

I use strpos to find the position of a line in another line. First, I check if the string is found there. Here is my line:

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

I check if both lines are contained, and then I want the first to be placed before the second. The php manual says strpos returns false when a string is not found. However, if my line starts at position zero (strpos returns 0 from the moment it started), it looks like this statement

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

is false. Somehow 0 == false? How to make a statement true when strpos returns 0?

+3
source share
3 answers

From http://www.php.net/manual/en/function.strpos.php :

Warning

Boolean , , FALSE, 0 ". Booleans . === .

=== ==.

<> !==:

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

TRUE, $ss1 $grafik['data']

+17

===. , false, 0.

+5

, , , ,

if(strpos($text,$string)===false)

$pos=strpos($text,$string); if($pos===false)

+3
source

Source: https://habr.com/ru/post/1775128/


All Articles