mb_stripos
大小写不敏感地查找字符串在另一个字符串中首次出现的位置
mb_stripos 函数适用于 PHP 4.0.6 及以上版本。
mb_stripos 函数用于查找一个字符串在另一个字符串中首次出现的位置(不区分大小写)。该函数是多字节字符串函数的一部分,专门用于处理多字节编码的字符串(如UTF-8)。
int mb_stripos ( string $haystack , string $needle [, int $offset = 0 ] )
如果在目标字符串中找到指定子字符串,函数返回首次出现的位置(基于 0 的索引)。如果未找到,则返回 FALSE。
下面是使用 mb_stripos 函数的一个简单示例:
<?php
$haystack = "Hello, World!";
$needle = "world";
$position = mb_stripos($haystack, $needle);
if ($position !== false) {
echo "子字符串 '$needle' 出现在目标字符串 '$haystack' 中,位置:$position";
} else {
echo "没有找到子字符串 '$needle'。";
}
?>
在此示例中,我们定义了一个目标字符串 `$haystack` 和一个待查找的子字符串 `$needle`。使用 `mb_stripos` 函数查找 `$needle` 在 `$haystack` 中首次出现的位置。由于 `mb_stripos` 不区分大小写,查找的结果是忽略了 'world' 和 'World' 的大小写差异。最终返回的 `$position` 是 `7`,即 "world" 在 "Hello, World!" 中首次出现的位置。