You can use a "positive lookahead" like this:
,(?=.*,)
The lookahead is the part in parens. It basically says "only replace this comma if there's another comma later in the string.
The code would look like this:
echo preg_replace('/,(?=.*,)/', '', $str);
I tested this with RegexBuddy to confirm it works: