Home > Article > Backend Development > Detailed explanation of PHP's methods and functions similar to indexof for processing strings
This article mainly introduces the relevant information on the detailed explanation of PHP's indexof-like method and function for processing strings. Friends in need can refer to the following
Detailed explanation of PHP's indexof-like method and function for processing strings
There are two functions or methods similar to indexof for processing strings in PHP. They are the strpos function and the stripos function. The usage of these two functions is similar.
When the strpos function processes a string, if it contains the string, it returns the position of the first occurrence of the string, and returns false if it does not appear. Sensitive to string case.
When the stripos function processes a string, if it contains the string, it returns the position of the first occurrence of the string, and returns false if it does not appear. String case insensitivity.
PHP strpos() function
Definition and usage
strpos() Function finds the first occurrence of a string within another string.
Note: The strpos() function is case-sensitive.
Note: This function is binary safe.
Syntax
strpos(string, find, start)
Parameter description
string : Required. Specifies the string to search for.
find: required. Specifies the string to search for.
start: optional. Specifies the location from which to start the search.
Return value
Returns the position of the first occurrence of a string in another string, or returns FALSE if the string is not found .
Note: The string position starts from 0, not from 1.
Example
<?php echo strpos('Hello world!', 'wo'); ?>
Output: 6
PHP stripos( ) Function
#Definition and usage
stripos() function finds the first occurrence of a string in another string Location.
Note: The stripos() function is not case-sensitive.
Note: This function is binary safe.
Syntax
stripos(string,find,start)
Parameter description
string : Required. Specifies the string to search for.
find: required. Specifies the string to search for.
start: optional. Specifies the location from which to start the search.
Return value
Returns the position of the first occurrence of a string in another string, or returns FALSE if the string is not found .
Note: The string position starts from 0, not from 1.
Example
<?php echo stripos('Hello world!', 'WO'); ?>
Output: 6
Thanks for reading, I hope it can help everyone, Thank you for your support to the PHP Chinese website!
Related recommendations:
Detailed explanation of conversion between arrays and XML processed by PHP
The above is the detailed content of Detailed explanation of PHP's methods and functions similar to indexof for processing strings. For more information, please follow other related articles on the PHP Chinese website!