What are the common pitfalls to avoid when using stripos function in PHP for string comparison?

One common pitfall to avoid when using the stripos function in PHP for string comparison is not checking for false return values. If the substring is not found within the main string, stripos will return false. This can lead to unexpected behavior if not handled properly. To avoid this pitfall, always check the return value of stripos and handle the case where it returns false accordingly.

$mainString = "Hello World";
$substring = "world";

if (stripos($mainString, $substring) !== false) {
    echo "Substring found!";
} else {
    echo "Substring not found!";
}