Welcome Guest, Not a member yet? Register   Sign In
Name splitter library?
#1

Hello people!

I just want to know if there's an existing PHP library file (for CodeIgniter or maybe a vanilla PHP) that splits a full name into parts:

i.e:

Bond, James E.

returns

PHP Code:
array(
 
   [first_name] => 'James',
 
   [last_name] => 'Bond',
 
   [middle] => 'E.'


I found this library called PHP Name Parser (https://github.com/joshfraser/PHP-Name-Parser), but it doesn't fit to my requirements. It actually works but the "LastName, FirstName MiddleName" pattern don't work with the library.


Thanks in advance.. Hope someone can help me.
Reply
#2

This one seems quite complete and handles middle names https://github.com/theiconic/name-parser

Haven't used it myself.
Reply
#3

The tool is great. But we have a problem.

I test the library with this name: "John James E. Bond".

The result returns like this:
PHP Code:
array(
    [
'firstName'] => 'John',
    [
'middleName'] => 'James E.',
    [
'lastName'] => 'Bond'


I've already installed that to my project via Composer.
Reply
#4

(08-09-2018, 08:56 PM)kaitenz Wrote: The result returns like this:
PHP Code:
array(
 
   ['firstName'] => 'John',
 
   ['middleName'] => 'James E.',
 
   ['lastName'] => 'Bond'


What would you like it to return as?
Reply
#5

(08-10-2018, 12:59 AM)Pertti Wrote:
(08-09-2018, 08:56 PM)kaitenz Wrote: The result returns like this:
PHP Code:
array(
 
   ['firstName'] => 'John',
 
   ['middleName'] => 'James E.',
 
   ['lastName'] => 'Bond'


What would you like it to return as?


The ['firstName'] should return as "John James". The ['middleName'] should return "E." and ['lastName'] should return "Bond".
Reply
#6

(This post was last modified: 08-10-2018, 11:06 PM by John_Betong.)

@kaitenz


example 001: Bond, James E.

example 002: John James E. Bond"

First example has surname first and second example has surname last! 

Reminds me of: https://en.wikipedia.org/wiki/Garbage_in,_garbage_out

It would help if there was a full list of possible names.

PHP Code:
echo ''$str "John James E. Bond";
$tmp explode(' '$str);
echo 
'<pre>';
 print_r($tmp);
echo 
'</pre><br>';

echo 
''$str 'Bond, James E.';
$tmp explode(' '$str);
echo 
'<pre>';
 print_r($tmp);
echo 
'</pre>'

Output:
Quote:John James E. Bond
Array
(
   [0] => John
   [1] => James
   [2] => E.
   [3] => Bond
)


Bond, James E.
Array
(
   [0] => Bond,
   [1] => James
   [2] => E.
)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB