Used in today’s project to remove the last character in the string
Original string 1,2,3,4,5,6,
Remove the last character "," and the final result is 1,2,3,4,5,6
The code is as follows:
The code is as follows:
The system’s own functions can also achieve this effect, two methods:
1) substr($str, 0, -1)
2)rtrim($str, ",")
substr
Get part of the string.
Syntax: string substr(string string, int start, int [length]);
Return value: string
Function type: Data processing
Content Description
This function extracts length characters from the start position of the string string. If start is a negative number, it starts from the end of the string. If the omitted parameter length exists but is a negative number, it means that the length character from the bottom is obtained.
Usage examples
The code is as follows:
PHP rtrim() function
Definition and Usage
The rtrim() function removes whitespace characters or other predefined characters starting from the end of a string. Same as chop() function.
Grammar
rtrim(string,charlist) parameter description
string required. Specifies the string to be converted.
charlist Optional. Specifies which characters are removed from the string.
If this parameter is not set, the following characters are all removed:
"
"t" - ASCII 9, tab
"n" - ASCII 10, new line
"x0B" - ASCII 11, vertical tab
"r" - ASCII 13, carriage return
" " - ASCII 32, space
Usage examples