Php how to remove any last commas

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

See the manual.


rtrim for example:

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

// foo,bar,blah,bleh