- array_splice: documentation ( source)
- implode: documentation ( source)
- trim: documentation ( source)
- preg_split: documentation ( source)
<?php
$clientContactName = "Annelie Sterling";
$split = preg_split('/ /', $clientContactName);
if(count($split) >= 2) { //no point in trying to match if we don't have both a first and last name
$firstname = trim(implode("", array_splice($split,0,1)));
$lastname = trim(implode("",$split));
}
echo $firstname;
echo "\n";
echo $lastname;