PHP code example of adci / full-name-parser

1. Go to this page and download the library: Download adci/full-name-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

adci / full-name-parser example snippets



use ADCI\FullNameParser\Parser;
// some code ...
$parser = new Parser();

$name = 'Mr. David Davis';
$nameObject = $parser->parse($name);

$this->assertEquals('Mr.', $nameObject->getAcademicTitle());
$this->assertEquals('David', $nameObject->getFirstName());
$this->assertEquals('Davis', $nameObject->getLastName());


use ADCI\FullNameParser\Parser;
// Some code...
// Example with advanced options.
$parser = new Parser(['part' => 'all', 'fix_case' => TRUE, 'throws' => FALSE]);
$name = 'DE LORENZO Y GUTIEREZ, Mr. JÜAN MARTINEZ (MARTIN) Jr.';
$nameObject = $parser->parse($name);

$this->assertEquals('Mr.', $nameObject->getAcademicTitle());
$this->assertEquals('Jüan', $nameObject->getFirstName());
$this->assertEquals('Martinez', $nameObject->getMiddleName());
$this->assertEquals('de Lorenzo y Gutierez', $nameObject->getLastName());
$this->assertEquals('Martin', $nameObject->getNicknames());
$this->assertEquals('Jr.', $nameObject->getSuffix());
$this->assertEquals([], $nameObject->getErrors());
// Some else code...
// And example with overriding suffixes and titles lists by short versions of lists.
$options = [
    'suffixes' => ['esq', 'jr', 'sr'],
    'academic_titles' => ['ms', 'mrs', 'mr'],
];
$parser = new Parser($options);
$nameObject = $parser->parse($name);