Article From:https://www.cnblogs.com/zhangyouwu/p/9125015.html

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, ",");

 

Similar Posts:

Leave a Reply

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