francislavoie / name-parser

A universal, language-independent name parser PHP library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

THE ICONIC Name Parser

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version Total Downloads License Dependency Status


This is a universal, language-independent name parser.

Its purpose is to split a single string containing a full name, possibly including salutation, initials, suffixes etc., into meaningful parts like firstname, lastname, initials, and so on.

It is mostly tailored towards english names but works pretty well with non-english names as long as they use latin spelling.

E.g. Mr Anthony R Von Fange III is parsed to

  • salutation: Mr.
  • firstname: Anthony
  • initials: R
  • lastname: von Fange
  • suffix: III


Supported patterns

This parser is able to handle name patterns with and without comma:

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

Supported parts

  • salutations (e.g. Mr, Mrs, Dr, etc.)
  • first name
  • middle names
  • initials (single letters, possibly followed by a dot)
  • nicknames (parts within parenthesis, brackets etc.)
  • last names (also supports prefixes like von, de etc.)
  • suffixes (Jr, Senior, 3rd, PhD, etc.)

Other features

  • multi-language support for salutations, suffixes and lastname prefixes
  • customizable nickname delimiters
  • customizable normalisation of all output strings (original values remain accessible)
  • customizable whitespace


More than 80 different successfully parsed name patterns can be found in the parser unit test.


composer require theiconic/name-parser


Basic usage


$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()); // all parts as an associative array

echo $name; // re-prints the full normalised name

An empty string is returned for missing parts.

Setting Languages

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

Setting nickname delimiters

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

Setting whitespace characters

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


THE ICONIC Name Parser library for PHP is released under the MIT License.

ezoic increase your site revenue


A universal, language-independent name parser PHP library

License:MIT License


Language:PHP 100.0%