The content of this article is to share with you an in-depth analysis of the strpos function in PHP. The content is very detailed. Friends in need can refer to it. I hope it can help you.
Overview
strpos is often used in PHP to determine whether a string exists in another string. This article introduces the strpos function and its implementation. .
Warning:strpos The function may return a Boolean value FALSE, but may also return the equivalent of # A non-Boolean value for ##FALSE. Please read the Boolean Types chapter for more information. The return value of this function should be tested using the === operator.
strpos series function
Function
Description
Version
strpos
Find the first occurrence of a string
PHP 4, PHP 5, PHP 7
stripos
Find the first occurrence of a string (not case sensitive)
PHP 5, PHP 7
strrpos
Calculate the specified character The position of the last occurrence of the string in the target string
PHP 4, PHP 5, PHP 7
strripos
Calculates the position of the specified string in the target The position of the last occurrence in a string (case-insensitive)
PHP 5, PHP 7
mb_strpos
Find a string that appears in another string The position of the first occurrence in the string
PHP 4 >= 4.0.6, PHP 5, PHP 7
strstr
Find the position of the string First appearance
PHP 4, PHP 5, PHP 7
stristr
case-ignoring version of strstr() function
PHP 4, PHP 5, PHP 7
substr_count
Count the number of occurrences of a string
PHP 4, PHP 5, PHP 7
mb* Related functions are also available. For example, mb_strpos performs a multi-byte safe strpos() operation based on the number of characters. PHP(strpos) source codestrpos(ext/standard/string.c)
/* 字符串函数memcmp
原型:extern int memcmp(void *buf1, void *buf2, unsigned int count);
功能:比较内存区域buf1和buf2的前count个字节
说明:当buf1<buf2时,返回值<0
当buf1=buf2时,返回值=0
当buf1>buf2时,返回值>0
*/
#ifndef __HAVE_ARCH_MEMCMP
#undef memcmp
__visible int memcmp(const void *cs, const void *ct, size_t count)
{
const unsigned char *su1, *su2;
int res = 0;
for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0)
break;
return res;
}
EXPORT_SYMBOL(memcmp);
#endif
TipThe strpos function is case-sensitive. Related recommendations:
Application of the lock mechanism in PHP
How to encrypt the php ID
The above is the detailed content of In-depth analysis of strpos function in PHP. For more information, please follow other related articles on the PHP Chinese website!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn