php字符串查找函数zend

Zend/zend_operators.h:static inline char * zend_memnstr(char *haystack, char *needle, int needle_len, char *end){//字符首指针char *p = haystack;//最后一个字符char ne = needle[needle_len-1];//减小查询范围,判断needle_len应该小于end还算比较巧妙哦end -= needle_len;while (p <= end) {//在数组的前n个字节中搜索字符 memchr(p, *needle, (end-p+1))if ((p = (char *)memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) {//如果找到首字节并且最后一个字节相同if (!memcmp(needle, p, needle_len-1)) {//对比找到啦那么返回首指针return p;}}if (p == NULL) {return NULL;}p++;}return NULL;}

php函数strpos、explode都用到了此函数,具体代码可以查看:ext/standard/string.c

版权声明:本文为博主原创文章,,未经博主允许不得转载。

离开睁眼闭眼看见的城市,逃离身边的纷纷扰扰,

php字符串查找函数zend

相关文章:

你感兴趣的文章:

标签云: