Removing last comma in a string – PHP

Hi guys, Here I am gonna share how to remove the last comma in a string by using php rtrim function.

The rtrim() function will remove whitespaces or other predefined character from the right side of a string.

Syntax

rtrim(string,charlist)
Example :

$text_with_comma = “1,2,3,4,5,6,7,”;

$removed = rtrim($text_with_comma, ‘,’);

Output :

1,2,3,4,5,6,7

Thanks!

You May Also Like

Never Miss Any Web Tutorials, Guides, Tips and Free eBooks

Join Our Community Of 50,000+ Web Lovers and get a weekly newsletter in your inbox

 

I hate spam too. Unsubscribe at any time.

Leave a Comment