php What is the function of strpos() function?
strpos() function finds the first occurrence of a string within another string. It should be noted that this function is case-sensitive, contrary to the php stripos() function, which is not case-sensitive. This article will take you through the php strpos() function.
php strpos() function syntax
strpos(string,find,start)
Detailed explanation of parameters:
This function has three parameters, of which the first two parameters are required Yes, the third parameter is optional
Parameter | Description |
---|---|
string | Required. Specifies the string to be searched for. |
find | Required. Specifies the characters to search for. |
start | Optional. Specifies the location from which to start the search. |
php The return value of strpos() function
strpos() function returns the first string in another string The position where the string appears first, or FALSE if the string is not found. String positions start at 0, not 1.
The related functions are:
stripos() - Find 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() - Find the last occurrence of a string in another string (case sensitive)
php strpos() function example
Use the php strpos() function to find the first occurrence of "php" in the string. The code is as follows:
<?php echo strpos("You love php, I love php too!","php"); ?>
Code Run the browser output result:
[Related article recommendations]
php Definition of string function stripos() And usage
Detailed explanation of php string function strripos() instance
Detailed explanation of string function strrpos()
The above is the detailed content of Detailed explanation of php strpos() function example. For more information, please follow other related articles on the PHP Chinese website!