3v4l.org

run code in 300+ PHP versions simultaneously
<?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;

preferences:
36.96 ms | 402 KiB | 5 Q