Splitting a name field into firstname/surname
Posted: Sun Jan 22, 2006 3:58 am
Hi there,
I have a single "name" input field, and when submitted I want to look for the first space in the name, put anything before it into a "firstname" field, and anything after it into "surname".
At the moment I'm doing it like this (because its the only way I know how):
However, if there's more than one space in the name - e.g. Billy Bob Thornton, it's ending up with Billy in the $firstname, Bob in the $surname, and Thornton is getting dropped. How do I get my $surname to pick up everything except the $firstname?
I have a single "name" input field, and when submitted I want to look for the first space in the name, put anything before it into a "firstname" field, and anything after it into "surname".
At the moment I'm doing it like this (because its the only way I know how):
Code: Select all
<?
$fullnameexplode = explode(' ', $fullname);
$firstname=$fullnameexplode[0];
$surname=$fullnameexplode[1];
?>