strstr() 和 strrchr()有一定的相似性,所以放在一起。
strstr
strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string
needle 可以为单个字符,也可以是个字符串。
返回 needle 在 haystack 在第一次出现的位置到结束,包括 needle。
before_needle 为true时,则返回needle之前的字符串,不包括 needle。strrchr
strrchr ( string $haystack , mixed $needle ) : string
返回 needle 在 haystack 在最后一次出现的位置到结束,包括 needle。
needle 必须为单个字符,多个字符只有第一个起作用。一个典型应用就是获取文件扩展名,如下
strtolower(strrchr($filename, '.'))
总结
两者的异同
strstr 中 needle 可以为字符串
strrchr 中 needle只能为单个字符,从名称上也能看出来。中间的r代表right,指从右边开始算起。既然有从右边开始算,那么肯定也应该有从左边开始算的,而且命名应该是 strlchr,按照惯例,l 可以省略,那就是 strchr,查了一下果然有,不过是 strstr 的别名,而且功能有所增强。目前来看,唯一不对称的就是命名和功能,不一致,不知道官方基于什么考虑。
详细解决方案
PHP的strstr() 和 strrchr() 函数怎么用! 详解
热度:3 发布时间:2023-11-14 06:39:12.0
相关解决方案
- strstr()函数 问题
- php基础学习- strstr() 函数
- php的 strstr() 函数效率高吗?该如何处理
- strrchr() 函数返回结果有时候不对
- php基础学习- strstr() 函数
- php的 strstr() 函数效率高吗?该如何处理
- substr(),strstr()函数
- [leetcode]双指针 Implement strStr
- LeetCode中每日一题28. 实现 strStr()的趣谈
- LeetCode 28 Implement strStr()
- PHP的strstr() 和 strrchr() 函数怎么用! 详解
- 28. 实现 strStr()-----leetcode刷题(python解题)
- Leetcode 28. 实现 strStr()(DAY 141) ---- LeetCode 精选 TOP 面试题
- 【LeetCode】栈合集 单调栈合集 84. 柱状图中最大的矩形 239. 滑动窗口最大值 28. 实现 strStr() 150. 逆波兰表达式求值 232. 用栈实现队列 581. 最短无序
- 【LeetCode】28. 实现 strStr() KMP easy
- strstr()函数
- 【C进阶】字符串函数(strlen、strcpy、strcat、strcmp、strncpy、strncat、strncmp、strstr、strtok、strerror)
- day(16) 字符串函数的模拟实现(strcat),(strstr)。
- C语言:strstr()函数用来检索子串在字符串中首次出现的位置
- 【力扣网练习题】实现 strStr()
- 模拟实现strlen,strcpy,strcmp,strstr,strcat,memcpy,memmove,memset
- (字符串)LC实现 strStr()
- 少见却强大酷炫的字符串函数(strtok/strstr/strerror)
- LeetCode:28. 实现 strStr()
- [LeetCode] 034: Implement strStr()
- leetcode-Algorithms-28|实现 strStr()
- PHP 字符串获取 substr 与 strstr 函数
- leetcode | Implement strStr() | 实现字符串查找函数
- 【定长滑动窗口】28. 实现 strStr()、567. 字符串的排列、1456. 定长子串中元音的最大数目
- [C/C++] 字符串处理函数 strstr 与 strncpy