PHP trim problem
<p>I <a href="http://stackoverflow.com/questions/3440635/php-how-to-remove-extra-characters-at-the-end-and-beginning-of-a-string">asked earlier</a> how can I get rid of extra hyphens and whitespace added at the end and beginning of user submitted text for example, <code>-ruby-on-rails-</code> should be <code>ruby-on-rails</code> you guys suggested <code>trim()</code> which worked fine by itself but when I added it to my code it did not work at all it actually did some funky things to my code. </p>

<p>I tried placing the <code>trim()</code> code every where in my code but nothing worked can someone help me to get rid of extra hyphens and whitespace added at the end and beginning of user submitted text?</p>

<p>Here is my PHP code.</p>

<pre><code>$tags = preg_split('/,/', strip_tags($_POST['tag']), -1, PREG_SPLIT_NO_EMPTY);
$tags = str_replace(' ', '-', $tags);
</code></pre>
