This article describes the character lookup function Strpos, STRRCHR and STRPBRK usage in PHP. Share to everyone for your reference. Specifically as follows:
The ①strpos () function returns the first occurrence of a string in another string, or False if the string is not found.
Syntax: Strpos (String,find,start), code as follows:
Copy Code code as follows:
$str = "Hello World"; Definition string 1
$result =strpos ($str, "ll"); Where to find the first occurrence
echo $result; Output results, 2
The ②STRRCHR () function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string, or False if it fails.
Syntax: STRRCHR (String,char), code as follows:
Copy Code code as follows:
$str = "Hello World"; Definition string 1
$result =STRRCHR ($str, "O"); Perform a lookup where the last occurrence
echo $result;
The ③STRPBRK () function searches the string for any one of the specified characters that returns the remainder of the beginning of the first occurrence of the specified character, or False if it is not found.
Syntax: STRPBRK (string,charlist), code as follows:
Copy Code code as follows:
$str = "Hello World"; Definition string 1
$result =strpbrk ($str, "oe"); Perform a Find operation
echo $result; Output results, Hello World
Tips and comments.
Note: This function is sensitive to case sensitivity.
I hope this article will help you with your PHP program design.