Php how to remove any last commas

大城市里の小女人 提交于 2019-12-28 02:41:06

问题


Example output

1. test,test,test,test,test,
2. test,test,test,,
3. test,test,,,
4. test,,,,,

I tried use implode according to my previous question but It's trim only last comma.

How to remove any last commas?


回答1:


rtrim('test,,,,,', ',');

See the manual.




回答2:


rtrim for example:

$str = 'foo,bar,blah,bleh,';
echo rtrim($str,',');

// foo,bar,blah,bleh



回答3:


completely different way:

$str = "1,2,3,4,";
$str = substr($str,0,strlen($str)-1);


来源:https://stackoverflow.com/questions/3120398/php-how-to-remove-any-last-commas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!