Mantemper
asked on
Split Full Contact Name
Hello experts,
I am looking for a solution for my problem.
I like to be able to split the FULL NAME to 2 parts or 3 parts
For example
Will X Smith
Bill Gate
The script should be able to to detect the
First name as Will
Middle Name as X
Lastname as Smith
so i guess the pattern is maybe like this
Search for number of space in the contact name
If found 1 space in the contact name then the first word is firstname the second word is last name
If found 2 space in the contact name then the 1st word is Firstname, 2nd is Middle initial, 3nd is last name.
Thank you to all.
I am looking for a solution for my problem.
I like to be able to split the FULL NAME to 2 parts or 3 parts
For example
Will X Smith
Bill Gate
The script should be able to to detect the
First name as Will
Middle Name as X
Lastname as Smith
so i guess the pattern is maybe like this
Search for number of space in the contact name
If found 1 space in the contact name then the first word is firstname the second word is last name
If found 2 space in the contact name then the 1st word is Firstname, 2nd is Middle initial, 3nd is last name.
Thank you to all.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
to Mantemper;
are you trying???
are you trying???
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm sorry guys, I was a little busy.
Wow so many solutions.
Thank to all of you very much.
Let me try your script.
$name = "Will X Smith";
$names = strtok($name, " ");
$first_name = array_shift($names);
$last_name = array_pop($names);
$middle_names = implode(" ",$names);
This should give you following:
First Name: Will
Last Name: Smith
Middle Names: X
Open in new window