PHP code example of blacksenator / name-parser

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

    

blacksenator / name-parser example snippets


... [firstname] ... [lastname] ...

... [lastname] ..., ... [firstname] ...

... [lastname] ..., ... [firstname] ..., [suffix]

[
'FN' => 'Otto Eduard Leopold Fürst von Bismarck-Schönhausen',
'N' => 'Bismarck-Schönhausen;Otto;Eduard,Leopold;;Fürst,von',
'NICKNAME' => '',
'ORG' => '',
]

[
'FN' => "Fürstlich von Bismarck'sche Brennerei GmbH",
'N' => '',
'NICKNAME' => '',
'ORG' => "Fürstlich von Bismarck'sche Brennerei GmbH",
]



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

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

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

print_r($name->getAll());

print_r($name->getVCardArray(true));

echo $name;

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

echo $name->getNickname(); // Der Eiserne Kanzler
echo $name->getNickname(true); // (Der Eiserne Kanzler)

echo $name->getGivenName(); // Otto Eduard Leopold

echo $name->getFullName();

$parser = new blacksenator\NameParser\Parser([
    new blacksenator\NameParser\Language\German(),  // default in this version
    new blacksenator\NameParser\Language\English(), // recommended
      //
])

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

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

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

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

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