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!
If you enjoyed this article, Get email updates (It’s Free)
http://w3lessons.info/wp-content/uploads/2011/12/IMG_29591-1024x711.jpghttp://w3lessons.info/wp-content/uploads/2011/12/IMG_29591-150x150.jpgKarthikeyan KPHPphp,tips & tricks
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. Syntaxrtrim(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!