Use strpos
. If the string is not found it returns false
, otherwise something that is not false
. Be sure to use a type-safe comparison (===
) as 0
may be returned and it is a falsy value:
if (strpos($string, $substring) === false) {
// substring is not found in string
}
if (strpos($string, $substring2) !== false) {
// substring2 is found in string
}