Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Files and directories not needed by consumers of the package.
# `composer require` ships only the files NOT marked export-ignore.

/.github export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/.tool-versions export-ignore
/phpstan-baseline.neon export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
push:
branches: [master]
pull_request:

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
tests:
name: Tests (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.3', '8.4', '8.5']
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- uses: shivammathur/setup-php@fcafdd6392932010c2bd5094439b8e33be2a8a09 # v2.37.0
with:
php-version: ${{ matrix.php }}
extensions: mbstring
coverage: none
tools: composer:v2
- uses: ramsey/composer-install@a8d0d959dab41457692a5e2041bd9b757a119e3f # v3.2.1
- run: composer audit
- run: vendor/bin/phpunit

static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- uses: shivammathur/setup-php@fcafdd6392932010c2bd5094439b8e33be2a8a09 # v2.37.0
with:
php-version-file: .tool-versions
coverage: none
tools: composer:v2
- uses: ramsey/composer-install@a8d0d959dab41457692a5e2041bd9b757a119e3f # v3.2.1
- run: vendor/bin/phpstan analyse --no-progress

code-style:
name: Code Style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- uses: shivammathur/setup-php@fcafdd6392932010c2bd5094439b8e33be2a8a09 # v2.37.0
with:
php-version-file: .tool-versions
coverage: none
tools: composer:v2
- uses: ramsey/composer-install@a8d0d959dab41457692a5e2041bd9b757a119e3f # v3.2.1
- run: vendor/bin/php-cs-fixer fix --dry-run --diff
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor/
/tests/coverage
/.phpunit.cache/
/.php-cs-fixer.cache
phpunit.xml
25 changes: 25 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([__DIR__.'/src', __DIR__.'/tests']);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PER-CS2.0' => true,
'@PHP83Migration' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'single_quote' => true,
'trailing_comma_in_multiline' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_namespace' => true,
'no_extra_blank_lines' => true,
'phpdoc_line_span' => [
'property' => 'multi',
'method' => 'multi',
'const' => 'multi',
],
])
->setFinder($finder)
->setCacheFile(__DIR__.'/.php-cs-fixer.cache');
8 changes: 0 additions & 8 deletions .scrutinizer.yml

This file was deleted.

1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
php 8.3
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2017 THE ICONIC
Copyright (c) 2026 Zachary Miller (CodeByZach)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
88 changes: 74 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# THE ICONIC Name Parser
# Name Parser

<!--
[![Build Status](https://travis-ci.org/theiconic/name-parser.svg?branch=master&t=201705161308)](https://travis-ci.org/theiconic/name-parser)
[![Coverage Status](https://coveralls.io/repos/github/theiconic/name-parser/badge.svg?branch=master&t=201705161308)](https://coveralls.io/github/theiconic/name-parser?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/theiconic/name-parser/badges/quality-score.png?b=master&t=201705161308)](https://scrutinizer-ci.com/g/theiconic/name-parser/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/theiconic/name-parser/v/stable?t=201705161308)](https://packagist.org/packages/theiconic/name-parser)
[![Total Downloads](https://poser.pugx.org/theiconic/name-parser/downloads?t=201705161308)](https://packagist.org/packages/theiconic/name-parser)
[![License](https://poser.pugx.org/theiconic/name-parser/license?t=201705161308)](https://packagist.org/packages/theiconic/name-parser)
-->

> **Fork notice**: This is a maintained fork of [theiconic/name-parser](https://github.com/theiconic/name-parser),
> which has been effectively dormant since ~2020. This fork targets PHP 8.3+
> (tested through 8.5), ships expanded English dictionary entries, and uses
> modernized tooling (PHPUnit 12, PHPStan 2, PHP-CS-Fixer, GitHub Actions).
> The library is framework-neutral at runtime and integrates cleanly into
> Laravel, Symfony, or vanilla PHP projects — no framework dependencies.

## Purpose
This is a universal, language-independent name parser.
Expand All @@ -24,7 +33,7 @@ E.g. **Mr Anthony R Von Fange III** is parsed to
- lastname: **von Fange**
- suffix: **III**

This package has been used by The Iconic in production for years,
The original library was used by The Iconic in production for years,
successfully processing hundreds of thousands of customer names.

## Features
Expand Down Expand Up @@ -60,20 +69,23 @@ This parser is able to handle name patterns with and without comma:
## Examples

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

## Setup
```$xslt
composer require theiconic/name-parser

```bash
composer require codebyzach/name-parser
```

Requires PHP 8.3 or newer (tested on 8.3, 8.4, and 8.5).

## Usage

### Basic usage
```php
<?php

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

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

Expand All @@ -91,6 +103,34 @@ echo $name;
```
An empty string is returned for missing parts.

### Laravel integration

The library is framework-neutral and ships no Laravel-specific glue (no
service provider, no facade). Bind it in your own `AppServiceProvider` if
you want it resolvable from the container:

```php
// app/Providers/AppServiceProvider.php
use CodeByZach\NameParser\Parser;

public function register(): void
{
$this->app->singleton(Parser::class);
}
```

Then inject or resolve as usual:

```php
use CodeByZach\NameParser\Parser;

public function store(Request $request, Parser $parser)
{
$name = $parser->parse($request->input('full_name'));
// ...
}
```

### Special part retrieval features
#### Explicit last name parts
You can retrieve last name prefixes and pure last names separately with
Expand Down Expand Up @@ -125,27 +165,27 @@ echo $name->getFullName(); // J. Peter M. Schluter

### Setting Languages
```php
$parser = new TheIconic\NameParser\Parser([
new TheIconic\NameParser\Language\English(), //default
new TheIconic\NameParser\Language\German(),
$parser = new CodeByZach\NameParser\Parser([
new CodeByZach\NameParser\Language\English(), //default
new CodeByZach\NameParser\Language\German(),
])
```

### Setting nickname delimiters
```php
$parser = new TheIconic\NameParser\Parser();
$parser = new CodeByZach\NameParser\Parser();
$parser->setNicknameDelimiters(['(' => ')']);
```

### Setting whitespace characters
```php
$parser = new TheIconic\NameParser\Parser();
$parser = new CodeByZach\NameParser\Parser();
$parser->setWhitespace("\t _.");
```

### Limiting the position of salutations
```php
$parser = new TheIconic\NameParser\Parser();
$parser = new CodeByZach\NameParser\Parser();
$parser->setMaxSalutationIndex(2);
```
This will require salutations to appear within the
Expand All @@ -156,7 +196,7 @@ the first half of the name parts.

### Adjusting combined initials support
```php
$parser = new TheIconic\NameParser\Parser();
$parser = new CodeByZach\NameParser\Parser();
$parser->setMaxCombinedInitials(3);
```
Combined initials are combinations of several
Expand Down Expand Up @@ -248,6 +288,26 @@ gist.
Of course this can also be used in more useful ways, e.g. to spell out
abbreviated titles, like `Prof.` as `Professor` etc. .

## Local development

This repo uses [mise](https://mise.jdx.dev/) (or [asdf](https://asdf-vm.com/))
for PHP version pinning via `.tool-versions`. After cloning:

```bash
mise install # installs the pinned PHP version
composer install # installs dev dependencies
composer test # run the test suite
composer analyse # run PHPStan
composer lint # check code style (dry-run)
composer lint:fix # apply code style fixes
```

## Contributors

- **The Iconic** ([@theiconic](https://github.com/theiconic)) — original library author
- **Zachary Miller** ([@CodeByZach](https://github.com/CodeByZach)) — fork maintainer

## License

THE ICONIC Name Parser library for PHP is released under the MIT License.
Released under the [MIT License](LICENSE). Original work © 2017 The Iconic;
fork modifications © 2026 Zachary Miller (CodeByZach).
35 changes: 29 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
{
"name": "theiconic/name-parser",
"name": "codebyzach/name-parser",
"description": "PHP library for parsing a string containing a full name into its parts",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Zachary Miller",
"email": "codebyzach@gmail.com"
},
{
"name": "The Iconic",
"email": "engineering@theiconic.com.au"
}
],
"require": {
"php": ">=7.1"
"php": "^8.3",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"php-coveralls/php-coveralls": "^2.1",
"php-mock/php-mock-phpunit": "^2.1"
"friendsofphp/php-cs-fixer": "^3.64",
"php-mock/php-mock-phpunit": "^2.15",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^12.0"
},
"autoload": {
"psr-4": {
"TheIconic\\NameParser\\": ["src/", "tests/"]
"CodeByZach\\NameParser\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\CodeByZach\\NameParser\\": "tests/"
}
},
"scripts": {
"analyse": "phpstan analyse",
"lint": "php-cs-fixer fix --dry-run --diff",
"lint:fix": "php-cs-fixer fix",
"test": "phpunit"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
}
}
Loading