首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[函数]grapheme_strstr()函数—用法及示例

发布于 2025-04-27 08:22:34
0
16

函数名称:grapheme_strstr() 函数描述:grapheme_strstr() 函数在一个字符串中搜索指定的子字符串,并返回从该子字符串开始的剩余部分。 函数用法:grapheme_str...

函数名称:grapheme_strstr()

函数描述:grapheme_strstr() 函数在一个字符串中搜索指定的子字符串,并返回从该子字符串开始的剩余部分。

函数用法:grapheme_strstr(string $haystack, string $needle, bool $before_needle = false): string|false

参数:

  • haystack:要搜索的字符串。
  • needle:要搜索的子字符串。
  • before_needle:可选参数,如果设置为 true,则返回 needle 之前的部分;如果设置为 false,则返回 needle 之后的部分。默认为 false。

返回值:如果找到了子字符串,则返回从该子字符串开始的剩余部分;如果未找到子字符串,则返回 false。

示例:

$haystack = "Hello, world!";
$needle = "world";

$result = grapheme_strstr($haystack, $needle);
echo $result; // 输出:world!

$result = grapheme_strstr($haystack, $needle, true);
echo $result; // 输出:Hello, 

在上面的示例中,我们使用 grapheme_strstr() 函数在字符串 "Hello, world!" 中搜索子字符串 "world"。第一个示例中,返回了从子字符串 "world" 开始的剩余部分 "world!"。第二个示例中,由于设置了 $before_needle 参数为 true,返回了子字符串 "world" 之前的部分 "Hello, "。

评论
一个月内的热帖推荐
啊龙
Lv.1普通用户

9545

帖子

31

小组

3242

积分

赞助商广告
站长交流