flipping the names around in php
<p>ok so i have a user field that has the user enter the full name and i need to flip the names around </p>

<pre><code> $pieces = explode(" ", $_POST['realname']);
 name = stripslashes($pieces[1] . "-" . $pieces[0]);
</code></pre>

<p>but the problem is that if they type in the field </p>

<p>i need the final output as jones-mark for sake of the requirements or if there is only mark then i need mark</p>

<pre><code>mark jones
</code></pre>

<p>all is well but if they type </p>

<pre><code>mark 
</code></pre>

<p>then the output is </p>

<pre><code>-mark
</code></pre>

<p>im sure there is a better way to do this</p>
