1. strposintstrpos (string $ haystack, mixed $ needle [, int $ offset0]) function: find the position of the first occurrence of a string. description: Return & nbsp; needle & nbsp; in & nbsp; the first digit position in haystack & nbsp. And & nbsp; 1. strpos
int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
Function:Locate the first occurrence of a string
Note:?needle
? In?haystack
? The position of the number that appears for the first time. And? Strrpos ()? Different, before PHP 5, this function can use a complete string?needle
And the entire string will be used.
Parameters:
haystack
Search for the string.
needle
If?needle
? If it is not a string, it will be converted to an integer and considered as the sequential value of the character.
offset
Optional?offset
? The parameter can be used to specify the slave?haystack
? To start searching. The position of the returned number is relative?haystack
.
Return value:Returns the location information with an integer. If no needle is found, strpos () returns a boolean value of FALSE.
Example 1: use =
Pay attention to this point:
if(strpos($mystring,$findme)){ //do something;}
This may cause unexpected results, because if the position is 0 (the first character), it is actually found, however, if the result is FALSE, it cannot be processed as expected.
? UseDisplayExample 2: Use! =
Example 3: offset
II. stripos
The method used by the strpos () function is the same. The only difference is that stripos is case insensitive.
III. strrpos
?int strrpos ( string $haystack , string $needle [, int $offset = 0 ] )
Function:Calculates the position of the last occurrence of the specified string in the target string.
Note:Returns the last numeric position of the needle in the haystack string. Note that in PHP4, needle can only be a single character. if needle is specified as a string, only the first character is used.
Parameters:
haystack
Search for this string.
needle
If?needle
It is not a string, it will be converted to an integer and considered as the sequential value of characters.
offset
You may find any length of the substring in the string. A negative value causes the query to end at the count position starting at the end of the string.
Return value:Returns the position of the needle. If not found, return?FALSE
.
Example 1: Check whether the string exists
Like strpos, it is easy to make a mistake between "finding at 0" and "no strings found.
Example 2: search by offset
IV. strripos
The method used by the strrpos () function is the same. The only difference is that strripos is case insensitive.