Home / Web Development / PHP / Removing last comma in a string – PHP

Removing last comma in a string – PHP

Hi Guys,
Here I am going to share how to remove the last comma in a string by using php function. The rtrim() function will helps you to remove whitespaces or other predefined character from the right side of a string.



Syntax

rtrim(string,charlist)

Parameter Description
charlist Optional. Specifies which characters to remove from the string. If omitted, all of the following characters are removed:

  • “\0” – NULL
  • “\t” – tab
  • “\n” – new line
  • “\x0B” – vertical tab
  • “\r” – carriage return
  • ” ” – ordinary white space
string Required. Specifies the string to check

Example




Output is:

1,2,3,4,5

The rtrim() function removes whitespace characters from the right side of a string.

  • ltrim() – Removes whitespace or other predefined characters from the left side of a string.
  • trim() – In both sides of a string, removes whitespace or other predefined characters.
    .




If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Loading Facebook Comments ...
Social Media Auto Publish Powered By : XYZScripts.com