Replacing excess whitespaces
<p>I need to remove excess whitespaces from my players usernames in my application (more than once space between letters) and replace them with a single whitespace.  I do not mind users having a single whitespace, but I need to remove multiple whitespaces next to each other.  Currently I achieve it this way:</p>

<pre><code>$replace_array=array('  ','   ','    ','     ','      ','       ','        ','             ','          ','           ','            ','             ','              ','               ');
$fill_array=array('','','','','','','','','','','','','','');

$user_name=str_replace($replace_array,$fill_array,trim($_POST['name']));
$user_name=preg_replace('/[^a-zA-Z0-9 ]/','',$user_name);
</code></pre>

<p>That seems entirely unnecessary to remove excess whitespaces.  Does, perhaps, the preg_replace function already handle excess whitespaces?  If not, what should I do to simplify this part of my code.</p>

<p>Thanks!</p>
