在 PHP 中,stripos() 函數本身是區分大小寫的
<?php
$haystack = 'Hello World';
$needle = 'WORLD';
$result = stripos($haystack, $needle);
if ($result !== false) {
echo "Found '$needle' in '$haystack' at position $result.";
} else {
echo "'$needle' not found in '$haystack'.";
}
?>
在這個例子中,我們使用了 stripos() 函數來查找子字符串 $needle 在 $haystack 中的位置。由于 stripos() 是不區分大小寫的,因此它會正確地找到子字符串 ‘WORLD’ 在 ‘Hello World’ 中的位置(即 6)。