How can PHP be used to perform a case-insensitive search for a word in a string?
To perform a case-insensitive search for a word in a string using PHP, you can use the `stripos()` function. This function finds the position of the first occurrence of a substring in a string, ignoring case. You can use this function to check if a specific word exists in a string without being case-sensitive.
$string = "Hello World";
$word = "hello";
if(stripos($string, $word) !== false) {
echo "The word '$word' was found in the string.";
} else {
echo "The word '$word' was not found in the string.";
}
Keywords
Related Questions
- What are potential pitfalls to avoid when working with FTP connections in PHP scripts?
- How can the EV A principle be applied to separate HTML output from PHP logic to improve code readability and security in PHP projects?
- Can you provide examples of how to efficiently work with arrays in PHP instead of dynamically creating variables?