This article mainly introduces the details of PHP processing string similar to IndexOf method function of the relevant data, the need for friends can refer to the following
A detailed explanation of how PHP handles string-like IndexOf method functions
There are two functions or methods that handle strings like indexof in PHP, which are strpos functions and STRIPOS functions, which are similar in usage.
When the Strpos function processes a string, it returns the first occurrence of the string if it contains the string, or False if it does not appear. Sensitive to string case.
When the Stripos function processes a string, it returns the first occurrence of the string if it contains the string, or False if it does not appear. Not sensitive to string case.
PHP Strpos () function
Definition and usage
The Strpos () function finds the position of the first occurrence of a string in another string.
Note: the Strpos () function is case-sensitive.
Note: This function is binary safe.
Grammar
Strpos (String, find, start)
Parameter description
String: Required. Specifies the string to search for.
Find: Required. Specifies the string to find.
Start: Optional. Specify where to start the search.
return value
Returns the position of the first occurrence of a string in another string, or FALSE if no string is found.
Note: The string position starts at 0, not from 1.
Example
<?phpecho strpos (' Hello world! ', ' wo ');? >
Output: 6
PHP Stripos () function
Definition and usage
The Stripos () function finds the position of the first occurrence of a string in another string.
Note: the Stripos () function is case insensitive.
Note: This function is binary safe.
Grammar
Stripos (String,find,start)
Parameter description
String: Required. Specifies the string to search for.
Find: Required. Specifies the string to find.
Start: Optional. Specify where to start the search.
return value
Returns the position of the first occurrence of a string in another string, or FALSE if no string is found.
Note: The string position starts at 0, not from 1.
Example
<?phpecho stripos (' Hello world! ', ' WO ');? >
Output: 6
Thank you for reading, hope to help everyone, thank you for the support of topic.alibabacloud.com!