What is the difference between strpos and stripos in PHP and when should each be used?

The main difference between strpos and stripos in PHP is that strpos is case-sensitive while stripos is case-insensitive when searching for a substring within a string. strpos returns the position of the first occurrence of the substring, while stripos returns the position of the first occurrence regardless of case. Use strpos when you need a case-sensitive search, and use stripos when you need a case-insensitive search.

// Using strpos for case-sensitive search
$string = "Hello World";
$substring = "world";
$pos = strpos($string, $substring);
if ($pos !== false) {
    echo "Substring found at position: " . $pos;
} else {
    echo "Substring not found";
}

// Using stripos for case-insensitive search
$string = "Hello World";
$substring = "world";
$pos = stripos($string, $substring);
if ($pos !== false) {
    echo "Substring found at position: " . $pos;
} else {
    echo "Substring not found";
}