PHP code example of theiconic / name-parser

1. Go to this page and download the library: Download theiconic/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/ */

    

theiconic / name-parser example snippets




$parser = new TheIconic\NameParser\Parser();

$name = $parser->parse($input);

echo $name->getSalutation();
echo $name->getFirstname();
echo $name->getLastname();
echo $name->getMiddlename();
echo $name->getNickname();
echo $name->getInitials();
echo $name->getSuffix();

print_r($name->getAll());

echo $name;

echo $name->getLastnamePrefix();
echo $name->getLastname(true); // true enables strict mode for pure lastnames, only

echo $name->getNickname(); // The Giant
echo $name->getNickname(true); // (The Giant)

echo $name->getGivenName(); // J. Peter M.

echo $name->getFullName(); // J. Peter M. Schluter

$parser = new TheIconic\NameParser\Parser([
    new TheIconic\NameParser\Language\English(), //default
    new TheIconic\NameParser\Language\German(),
])

$parser = new TheIconic\NameParser\Parser();
$parser->setNicknameDelimiters(['(' => ')']);

$parser = new TheIconic\NameParser\Parser();
$parser->setWhitespace("\t _.");

$parser = new TheIconic\NameParser\Parser();
$parser->setMaxSalutationIndex(2);

$parser = new TheIconic\NameParser\Parser();
$parser->setMaxCombinedInitials(3);

$parser = new Parser();
$name = $parser->parse($input);
$name = $parser->parse((string) $name);
...