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?
To remove the last comma from a string, call the replace() method with the following regular expression /,*$/ as the first parameter and an empty string as the second. The replace method will return a new string with the last comma removed. Copied!
You can use the PHP substr_replace() function to remove the last character from a string in PHP. $string = "Hello TecAdmin!"; echo "Original string: " . $string .
rtrim('test,,,,,', ',');
See the manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With