Skip to main content
Home / Code Snippets / PHP / Separate First and Last Name

Separate First and Last Name

$name = "John S Smith";

list($fname, $lname) = split(' ', $name,2);

echo "First Name: $fname, Last Name: $lname";

Works with or without middle name.