PHP Split a sting if it has a space and detect if its been split
<p>I need to pass two variables with no spaces to a web service so that i dont get an invalid response.</p>

<p><code>$firstname</code> and <code>$surname</code></p>

<p>I need to make these variables from a variable called <code>$display_name</code></p>

<p>Display name may or may not contain a space. It will usually be something like 'Joe Smith' or 'JoeSmith'</p>

<p>So i cant just do (because with 'JoeSmith' I will get no surname)</p>

<pre><code>$pieces = explode(" ", $display_name);
$firstname = $pieces[0]; // Joe
$surname   = $pieces[1]; // Smith
</code></pre>

<p>likewise i cannot do (because of the potential space)</p>

<pre><code>$firstname = $display_name; // Joe Smith
$surname   = $display_name; // Joe Smith
</code></pre>

<p>How can i ensure both firstname and surname are populated with no spaces. Even if the display name was 'Joe T Smith'?</p>
