Home > Article > Backend Development > How to remove the last character from php string
How to delete the last character in a php string: First create a PHP sample file; then use the "substr($str,0,strlen($str)-1);" method to delete the last character in the specified string Just delete the last character.
Recommended: "PHP Video Tutorial"
php Remove the last character of the string
Original string 1,2,3,4,5,6,
Remove the last character ",", the final result is 1,2,3,4,5,6
The code is as follows:
$str = "1,2,3,4,5,6,"; $newstr = substr($str,0,strlen($str)-1); echo $newstr; //echo 1,2,3,4,5,6
The function that comes with the system can achieve this effect, two methods:
substr($str, 0, -1) //函数2 rtrim($str, ",")
The above is the detailed content of How to remove the last character from php string. For more information, please follow other related articles on the PHP Chinese website!