Article From:

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 system’s own functions can achieve this effect. The two way is:

//Function 1
substr($str, 0, -1);
//Function 2
rtrim($str, ",");


Leave a Reply

Your email address will not be published. Required fields are marked *