原字符串1,2,3,4,5,6,
去掉最后一個字符",",最終結果為1,2,3,4,5,6
代碼如下:
$str = "1,2,3,4,5,6,";
$newstr = substr($str,0,strlen($str)-1);
echo $newstr;
//echo 1,2,3,4,5,6
系統自帶的函數即可實現這樣的效果,兩種方法:
substr($str, 0, -1)
//函數2
rtrim($str, ",")
去掉最后一個字符",",最終結果為1,2,3,4,5,6
代碼如下:
$str = "1,2,3,4,5,6,";
$newstr = substr($str,0,strlen($str)-1);
echo $newstr;
//echo 1,2,3,4,5,6
系統自帶的函數即可實現這樣的效果,兩種方法:
substr($str, 0, -1)
//函數2
rtrim($str, ",")