This article mainly introduces string related functions in php. Interested friends can refer to it. I hope it will be helpful to everyone.
1. Function to find character position:
strpos(
The first occurrence in str The position of
stripos($str,search,[int]): Returns the position of the first occurrence of a string in another string. This function is useful for Case insensitive
strrpos(
The last occurrence of str in position, starting from int
strripos($str,search,[int]): Same as above, but is not case sensitive
2. Extract substring function ( Double bytes)
substr($str,int start[,int length]): Intercept the length string starting from the start position. If length is empty, intercept it to the end
strstr(
str2): intercept from
str2 from the beginning to the end, if not Then return false
stristr(
##str2): The function is the same as strstr, but it is not case sensitive##str2): intercept backwards from the last searched character; Can be used to get the file name
3. Replace the string
Search search in str
##str_ireplace(search,replace,$str): Same as above, this function is not case sensitive
rep ,
str original string,
start starting position, $length replacement The length of
int strcmp(str2):
str2 respectively Is positive 1,0,-1 (string comparison)
strcasecmp() Same as above (not case sensitive)strnatcmp("4", "14") Compare strings in natural order strnatcasecmp() Same as above, (case sensitive)
6. PHP string function split into arraysstr_split(str is split according to the length of len and returns the array
split(search,str is divided according to the search character and the returned array int is divided several times, and the subsequent ones will not be divided expload(search,$str[,int])
ltrim(), rtrim(), trim()Related recommendations:
PHP characters String definition methods and their differences
The above is the detailed content of String related functions in php. For more information, please follow other related articles on the PHP Chinese website!