looking for a way to strip a trailing comma from string only if one is there php
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://facebook.stackoverflow.com/questions/2053830/php-remove-last-character-if-its-a-period">PHP - Remove last character if it’s a period?</a>  </p>
</blockquote>



<p>I am trying to strip a trailing comma from a string.  I do it like this:</p>

<pre><code>$_POST['city_id_list'] //looks like 1,4,213,
$trimmed = substr(trim($_POST['city_id_list']),0,-1);
</code></pre>

<p>But what if the last character is not a comma?</p>

<p>java has something like:</p>

<pre><code>str.replaceAll(" ,$", "")
</code></pre>

<p>I assume there is a way to do this with PHP.  What is the best way to do it?</p>
