• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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, 09: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, 01:59 AM)Pertti Wrote:
(08-09-2018, 09: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
@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.
)
CI4 Develop Site - progressing nicely - Thank you Smile
https://johns-jokes.cf/pictures

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.