原字符串1,2,3,4,5,6,
去掉最后一個字符",",最終結(jié)果為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
系統(tǒng)自帶的函數(shù)即可實現(xiàn)這樣的效果,兩種方法:
substr($str, 0, -1)
//函數(shù)2
rtrim($str, ",")
去掉最后一個字符",",最終結(jié)果為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
系統(tǒng)自帶的函數(shù)即可實現(xiàn)這樣的效果,兩種方法:
substr($str, 0, -1)
//函數(shù)2
rtrim($str, ",")