I have a string like
a,b,c,d,e,
I would like to remove last ',' and get the remaining string back
OUTPUT
a,b,c,d,e
Another string like
a,b,,,
OUTPUT
a,b
I have a string like
a,b,c,d,e,
I would like to remove last ',' and get the remaining string back
OUTPUT
a,b,c,d,e
Another string like
a,b,,,
OUTPUT
a,b
If you just want to remove the ,
on the right side, you could use rtrim
, if you need also the left side, trim
is your choice. If there are also some ,
inside, you could split and merge the string again.
$data = join(',', array_filter(explode(',', $data)));
The rtrim()
function removes whitespace or other predefined characters from the right side of a string.
For more details rtrim PHP
rtrim("a,b,,,", ",");