Present names for English-language applications where a first and last name combined is sufficient. This approach does not cover all possible naming cases, deal with other languages or titles.
This is a rough port of the Ruby package of the same name from Basecamp.
You can install the package with Composer using the following command:
composer require imliam/php-name-of-person:^1.1
The package supplies a single class that can be instantiated with a string containing the original name of a person.
The class has a handful of methods that can be called to return different variations of the supplied name.
use ImLiam\NameOfPerson\Name;
$name = new Name('David Heinemeier Hansson');
$name->getFullName(); // "David Heinemeier Hansson"
$name->getFirstName(); // "David"
$name->getLastName(); // "Heinemeier Hansson"
$name->getInitials(); // "DHH"
$name->getInitials(true); // "D.H.H."
$name->getFamiliar(); // "David H."
$name->getAbbreviated(); // "D. Heinemeier Hansson"
$name->getSorted(); // "Heinemeier Hansson, David"
$name->getMentionable(); // "davidh"
$name->getPossessive(); // "David Heinemeier Hansson's"
$name->getProperName(); // "David Heinemeier Hansson"
These methods take care to handle some of the situations that are often awkward to process and missed when handling names that come from user-input so aren't always reliable.
One such example is that names with particles can be capitalised properly with the getProperName()
method.
(new Name("lucas l'amour"))->getProperName(); // "Lucas l'Amour"
(new Name('t. von lieres und wilkau'))->getProperName(); // "T. von Lieres und Wilkau"
composer test
Please see the changelog file for more information on what has changed recently.
Please see the upgrading file for details on upgrading from previous versions.
Please see the contributing file and code of conduct for details on contributing to the project.
If you discover any security related issues, please email liam@liamhammett.com instead of using the issue tracker.
The MIT License (MIT). Please see the license file for more information.