Php how to remove any last commas

前端 未结 3 1118
遇见更好的自我
遇见更好的自我 2020-11-29 04:15

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 q

相关标签:
3条回答
  • 2020-11-29 04:59
    rtrim('test,,,,,', ',');
    

    See the manual.

    0 讨论(0)
  • 2020-11-29 05:01

    completely different way:

    $str = "1,2,3,4,";
    $str = substr($str,0,strlen($str)-1);
    
    0 讨论(0)
  • 2020-11-29 05:08

    rtrim for example:

    $str = 'foo,bar,blah,bleh,';
    echo rtrim($str,',');
    
    // foo,bar,blah,bleh
    
    0 讨论(0)
提交回复
热议问题