Normalize spaces in a string?
<p>I need to normalize the spaces in a string:</p>

<ol>
<li>Remove multiple adjacent spaces</li>
<li>Remove spaces at the beginning and end of the string</li>
</ol>

<p>E.g. <code>"  my name    is   "</code> => <code>my name is</code></p>

<p>I tried </p>

<pre><code>str_replace('  ',' ',$str);
</code></pre>

<p>I also tried <a href="http://stackoverflow.com/questions/2368539/php-replacing-multiple-spaces-with-a-single-space">php Replacing multiple spaces with a single space</a> but that didn't work either.</p>
