Home >Backend Development >PHP Tutorial >PHP string interception tutorial
获Php string Get SUBSTR and StRSTR Function
Recommended tutorial: Php online tutorial
to obtain specified characters from the string string. Relevant functions are as follows:
●substr(): Get a part of it from a string ●strstr(): Find the position where the string first appears in another string, and return the position from that position to All characters at the end of the string ●subchr(): Same as strstr() ●strrchr(): Find the last occurrence of a string in another string and return all characters from that position to the end of the string Character substr()Syntax:
strrchr(): The function is used to get a part of it from a string and return a string.string substr ( string string, int start [, int length] )The parameter description is as follows:
string | The string to be processed |
---|---|
start | Start position of the string, the starting position is 0, if it is negative, start from Starting from the specified position at the end of the string |
length | |
Example: |
Tips: If start is a negative number and length is less than or equal to start, then length is 0.
strstr()
Find the first occurrence of a string in another string and return all characters from that position to the end of the string, or FALSE if not found. Syntax:
string strstr ( string string, string needle )
The parameter description is as follows:
string | The string to be processed |
---|---|
needle | To be The string to search for, if it is a number , then search for characters matching the numeric ASCII value |