查询

grapheme_stristr()函数—用法及示例

「 在一个字符串中查找指定的子字符串,并返回从该子字符串开始到字符串结尾的部分字符串(不区分大小写) 」


函数名:grapheme_stristr()

适用版本:PHP 5 >= 5.3.0, PHP 7

用法:grapheme_stristr() 函数在一个字符串中查找指定的子字符串,并返回从该子字符串开始到字符串结尾的部分字符串(不区分大小写)。该函数使用 Unicode 安全的、语言感知的方式进行查找。

语法:grapheme_stristr(string $haystack, string $needle, bool $before_needle = false): string|false

参数:

  1. $haystack(必需):要在其中查找子字符串的字符串。
  2. $needle(必需):要查找的子字符串。
  3. $before_needle(可选):如果设置为 true,则返回 needle 之前的部分字符串;如果设置为 false(默认),则返回 needle 之后的部分字符串。

返回值:返回找到的子字符串及其后面的部分,如果未找到子字符串,则返回 false。

示例:

$haystack = "Hello, World!";
$needle = "world";
$result = grapheme_stristr($haystack, $needle);
var_dump($result); // 输出: string(7) "World!"

$haystack = "Hello, World!";
$needle = "hello";
$result = grapheme_stristr($haystack, $needle);
var_dump($result); // 输出: string(13) "Hello, World!"

$haystack = "Hello, World!";
$needle = "world";
$result = grapheme_stristr($haystack, $needle, true);
var_dump($result); // 输出: string(6) "Hello,"

注意:grapheme_stristr() 函数是 Unicode 安全的,可以正确处理多字节字符。

补充纠错
上一个函数: grapheme_strlen()函数
下一个函数: grapheme_stripos()函数
热门PHP函数
分享链接