7 March 2024

To check if a string contains another string in PHP in a case-insensitive manner, you can use the stripos() function. stripos() returns the position of the first occurrence of a substring in a string, or false if the substring is not found, and it performs a case-insensitive search.

Source code viewer
  1. $string = "Hello World";
  2. $substring = "hello";
  4. if (stripos($string, $substring) !== false) {
  5. echo "Substring found in the string.";
  6. } else {
  7. echo "Substring not found in the string.";
  8. }
Programming Language: PHP