您的位置:首页 > 编程语言 > PHP开发

php内部函数

2016-04-18 13:37 489 查看
strpos函数

/**
haystack:被比较字串首地址(指向被比较字符串)
needle:源字串首地址(指向源字符串)
needle_len:源字符串长度
end:指向最后一个字符地址的下一个内存地址
**/
static inline char *
zend_memnstr(char *haystack, char *needle, int needle_len, char *end)
{
char *p = haystack;               //被比较字符串首地址
char ne = needle[needle_len-1];    //源字符串的最后一个字符

if (needle_len == 1) {
return (char *)memchr(p, *needle, (end-p));   //返回被比较字符串第一次出现的地址
}

if (needle_len > end-haystack) {    //源字符串超过被比较字符串的长度
return NULL;
}

end -= needle_len;   //end = end - needle_len  //最后比较的位置

while (p <= end) {
if ((p = (char *)memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) {   //比较首尾字符是否相等
if (!memcmp(needle, p, needle_len-1)) {     //用来比较needle 和p 所指的内存区间前needle_len-1个字符
return p;
}
}

if (p == NULL) {
return NULL;
}

p++;
}

return NULL;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: