PHP split string into uneven parts I am trying to split a string so that the first word goes into the first span, and the remaining (an unknown number of words) goes into the next.

This currently works fine, but is there an easy / faster / tidier way to do it ?

&lt;?
// Explode the job role out and combine into the two spans

    $la_jobrole = explode(' ', $lo_designer-&gt;role);
    $ls_jobPrimary = '';
    $ls_jobSecondary = '';
    $i=0;
    foreach($la_jobrole as $role) {
        if ($i == 0) $ls_jobPrimary = $role;
        else {
            $ls_jobSecondary .= $role . " ";
        }
        $i++;
    }

?&gt;
&lt;div class="designer"&gt;&lt;span&gt;&lt;?= $ls_jobPrimary ?&gt; &lt;/span&gt;&lt;span&gt;&lt;?= $ls_jobSecondary ?&gt;&lt;/span&gt;&lt;/div&gt;
explode and implode are faster (according to PHP's man page for preg_split), and more readable IMO.

$la_jobrole = explode(' ', $lo_designer-&gt;role);
$ls_jobPrimary = array_shift($la_jobrole); // Get the first item from the array
$ls_jobSecondary = implode(' ', $la_jobrole); // Glue the remaining pieces back together


Personally I would avoid using either list or preg_replace in this case. They're slower and harder to read, and I would certainly avoid that looping thing.