PHPackages                             blacksenator/name-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. blacksenator/name-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

blacksenator/name-parser
========================

PHP library for parsing a string containing a full name into its parts

v1.2.12(6y ago)01.8kMITPHPPHP &gt;=7.1

Since May 10Pushed 6y agoCompare

[ Source](https://github.com/blacksenator/name-parser)[ Packagist](https://packagist.org/packages/blacksenator/name-parser)[ Docs](https://github.com/blacksenator/name-parser)[ RSS](/packages/blacksenator-name-parser/feed)WikiDiscussions next Synced 2d ago

READMEChangelogDependencies (3)Versions (29)Used By (0)

php Name Parser
===============

[](#php-name-parser)

This is an enhanced version of [THE ICONIC name parser](https://github.com/theiconic/name-parser) with some adjustments mainly for german particularities.

Purpose
-------

[](#purpose)

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 german and english names but works pretty well as long as they use latin spelling.

E.g. **Otto Eduard Leopold Fürst von Bismarck-Schönhausen** is parsed to

- firstname: **Otto**
- middle names: **Eduard Leopold**
- prefix: **von**
- lastname: **Bismarck-Schönhausen**
- extension: **Fürst**

Features
--------

[](#features)

### Supported patterns

[](#supported-patterns)

This parser is able to handle name patterns with and without comma. Without a comma, the string is first compared against **identifiers for company names** ('GmbH'., 'Co. KG' etc). If so, parsing is skipped and the whole string will be marked as a company name.

Otherwise, the assumption is that a persons name and is in the following pattern:

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

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

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

### Needles in a haystack

[](#needles-in-a-haystack)

The strings used to search for characteristics for e.g. company names can be found in the folder `../src/Language`. I have added about a hundred string patterns, which I believe can be used to identify companies (may need to be supplemented).

### Supported parts

[](#supported-parts)

- salutations (e.g. Hr, Fr 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 etc.)
- titles (academic titles like Dr. med., Dr.h.c. etc)
- lastname extensions (nobility predicates like Gräfin, Baron)

### vCard Suppport

[](#vcard-suppport)

You can get an array whose keys match the properties for names - corresponding to [RFC 6350](https://tools.ietf.org/html/rfc6350):

So for example, **Bismarck-Schönhausen, Otto Eduard Leopold Fürst von** is converted to:

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

But a company like the **Fürstlich von Bismarck'sche Brennerei GmbH** becomes:

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

### Other features

[](#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

Examples
--------

[](#examples)

More than 60 different successfully parsed name patterns can be found in the [parser unit test](https://github.com/blacksenator/name-parser/blob/master/tests/ParserTest.php#L12-L12).

Setup
-----

[](#setup)

```
composer require blacksenator/name-parser

```

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

```
