Home >Backend Development >PHP Tutorial >PHP removes the last character from a string_PHP tutorial
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:
$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:
1) substr($str, 0, -1)
2)rtrim($str, ",")
Excerpted from 〃Style ひぐ