Name of Person is a PHP package inspired by Basecamp's name_of_person Ruby gem, which gives you intelligent parsing and multiple formatting options.
Handle person names in your PHP applications with elegant formatting options. Transform names between multiple presentation formats. This package provides a clean, type-safe way to parse, store, manipulate, and display person names consistently across your application.
use HosmelQ\NameOfPerson\PersonName; // Direct instantiation with first and last name.$name = new PersonName('Eric', 'Barnes'); // From full name strings.$parsed = PersonName::fromFull('Yannick Lyn Fatt'); echo $parsed->first; // "Yannick"echo $parsed->last; // "Fatt" // Handles single names.$single = PersonName::fromFull('Harris'); echo $single->first; // "Harris"echo $single->last; // null
This package also has Laravel support for casts that you can use with your models. The cast supports string-based cast config as well as a fluent method, and JSON serialization:
use HosmelQ\NameOfPerson\PersonNameCast; // Default configuration - uses first_name and last_name columnsclass User extends Model{ protected function casts(): array { return [ 'name' => PersonNameCast::class, ]; }} $user->name = 'Eric L. Barnes'; echo $user->name->familiar(); // "Eric B."echo $name->initials(); // "ELB"echo $name->possessive('first'); // Eric's // Fluent castreturn [ 'author_name' => PersonNameCast::using('author_first', 'author_last'),];
Main Features
- Multiple Format Options: nine different ways to display names (full, familiar, abbreviated, initials, sorted, possessive, mentionable)
- Smart Parsing: Intelligently handles full name strings and edge cases
- Unicode Support: Full international name support with proper multibyte handling
- Pure PHP: Core functionality works in any PHP project
- Laravel Integration: Native Eloquent casting for seamless database integration
👩💻 Get started by visiting the GitHub repo: hosmelq/name-of-person