There was an old post on this topic, and the question went something like below:
"Hi, I got a feed in which one of the 'childs' look like this
A product, B product, C product, D product, E product,
I was wondering how to remove the last comma."
A few suggestions were using eregi_replace() or substr(). Even though substr() suggestion was pretty clever (see below), it is simply chopping out the last character regardless it is a comma or not. And eregi_replace function has been deprecated as of PHP 5.3.0. My suggestion is to use preg_replace() instead.
For comparison purposes, I listed both substr() and preg_replace() example below. Enjoy and please comment/suggest new ways if you wish.
$str = "A product, B product, C product, D product, E product,";
$str = substr($str, 0, -1); //this will removed the last char in $str
-OR-
$mystr = "A product, B product, C product, D product, E product,";
//do this optionally for just in case any space or \n was added at the end
$mystr = trim($mystr);
$mystr = preg_replace('/,$/','',$mystr);
That is it!