Php string contains comparison replacement if (strpos ($ str ,?? 'OK ')! = False ){??? // Include }?? // Error method ?? If (strpos ($ str ,?? 'OK ')){...??} To determine whether the string $ str contains the 'OK' php string.
If (strpos ($ str ,?? 'OK ')! = False ){?
?? // Contains
}
?
?
// Incorrect method
?
?
If (strpos ($ str ,?? 'OK ')){...??}
To determine whether the string $ str contains 'OK', but recently it was found that a string with 'OK' was not found successfully. Sadly, this string starts with 'OK'. how can it not be found?
Find the strpos function definition, and srtpos returns the first position of the string that appears. this position starts from 0, for example, in 'It' s OK! ', The location of' OK 'is 5. If no value is found, false is returned. Found the problem: PHP variable types are weak and can be converted to variable types at will. 0 can be regarded as an integer or Boolean false, add strpos to determine whether the position of the string to be searched appears at 0. the function returns 0. is the if statement regarded as 0 or false? It seems that this is the problem.
Find the problem and the solution is available. add one character before the searched string.Not included inThe character in the keyword is enough, so as long as it is matched, the returned result will always be greater than or equal to 1.
?
?
?
?
?