In PHP, you can use the strpos() function to determine that a string does not contain another string. The implementation code is "if (strpos($a, 'are') !== false) {. ..} else {...}".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How does php determine that a string does not contain a certain character? Determine whether a string contains another string?
We can use the strpos() function to determine whether the string contains another string:
$a = 'How are you?'; if (strpos($a, 'are') !== false) { echo 'true'; } else { echo 'false'; }
Note that you must use !== false to make the judgment conditional statement, strpos( ) If the string is not found, it returns FALSE. If another string is found at the beginning of the string, it returns 0. Other positions are integers greater than 0, so we cannot use code like this!strpos( $a, 'are'), this will lead to misjudgment.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine if a string does not contain a certain character in php. For more information, please follow other related articles on the PHP Chinese website!