![]() |
VOOZH | about |
Checking whether a string contains a specific substring is a common task in PHP. Whether you're parsing user input, filtering content, or building search functionality, substring checking plays a crucial role.
Below are the following methods by which we can check if a string contains a substring in PHP:
str_contains() (PHP 8+)Output:
Substring found!Output:
Substring found!stripos()Output:
Substring found (case-insensitive)!preg_match()str_contains() for simple checks (if PHP 8+).strpos with !== false, not != false.stripos() for case-insensitive searches.preg_match() only for complex pattern matching.