I want to remove the comma off the end of a string. As it is now I am using
$string = substr($string,0,-1);
but that only removes the last character of the string. I am adding the string dynamically, so sometimes there is no comma at the end of the string. How can I have PHP remove the comma off the end of the string if there is one at the end of it?
Advertisement
Answer
$string = rtrim($string, ',');