Question

Php how to remove any last commas

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?

 45  84714  45
1 Jan 1970

Solution

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

See the manual.

2010-06-25

Solution

 35

rtrim for example:

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

// foo,bar,blah,bleh
2010-06-25