How to delete the last character in php: You can use the rtrim() function, such as [rtrim ($text, ",");]. The rtrim() function can remove blank characters or other characters at the end of a string.
Method 1:
rtrim removes the blank characters (or other characters) at the end of the string
( Recommended tutorial: php video tutorial)
Description:
string rtrim ( string $str [, string $character_mask ] )
This function deletes the blank characters at the end of str and returns.
Without the second parameter, rtrim() only removes the following characters:
##$str input string. $ character_mask By specifying character_mask, you can specify the character list you want to delete. Simply list all the characters you want to remove. Using the .. format, a range can be specified. Example:$text = 'b,c,d,'; $trimmed = rtrim ( $text , "," ); var_dump ( $trimmed );
b,c,d
string substr ( string $string , int $start [, int $length ] )
$str = 'a,b,c,d,'; $rest = substr( $str,0,strlen($str)-1); echo $rest;
a,b,c
The above is the detailed content of How to delete the last character in php. For more information, please follow other related articles on the PHP Chinese website!