What is the function of PHP strpos ()?
The Strpos () function finds the position of the first occurrence of a string in another string. It is important to note that this function is case-sensitive and, contrary to the PHP Stripos () function, the Stripos () function is case insensitive. This article leads you to the PHP Strpos () function.
Syntax for PHP strpos () function
Strpos (String,find,start)
Detailed parameters:
The function has three parameters, where the first two parameters are necessary, the third parameter is optional
Parameters |
Description |
String |
Necessary. Specifies the string to be searched. |
Find |
Necessary. Specifies the character to find. |
Start |
Optional. Specify where to start the search. |
The return value of the PHP Strpos () function
The Strpos () function returns the position of the first occurrence of a string in another string, or FALSE if no string is found. The string position starts at 0, not starting from 1.
The functions associated with them are:
Stripos ()-finds the position of the first occurrence of a string in another string (case insensitive)
Strripos ()-Finds the last occurrence of a string in another string (case insensitive)
Strrpos ()-Finds the last occurrence of a string in another string (case-sensitive)
PHP Strpos () Function Example
Use the PHP strpos () function to find the location of the first occurrence of "PHP" in the string, with the following code:
<?phpecho Strpos ("You love php, I love php too!", "PHP"); >
The code runs the browser output result:
"Related articles recommended"
The definition and usage of PHP string function Stripos ()
PHP string Function Strripos () example
Detailed string function Strrpos ()