PHPackages                             tamtamchik/namecase - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tamtamchik/namecase

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tamtamchik/namecase
===================

This package allows you to convert names into the correct case where possible.

3.0.0(3y ago)78506.0k—3.4%7[1 PRs](https://github.com/tamtamchik/namecase/pulls)MITPHPPHP &gt;=7.3

Since Jan 29Pushed 1y ago3 watchersCompare

[ Source](https://github.com/tamtamchik/namecase)[ Packagist](https://packagist.org/packages/tamtamchik/namecase)[ Docs](https://github.com/tamtamchik/namecase)[ RSS](/packages/tamtamchik-namecase/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (23)Used By (0)

NameCase
========

[](#namecase)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c872b1a73e8e6d76019c3f90607542c09d744948a65b809aef8f9edafcb799f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74616d74616d6368696b2f6e616d65636173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tamtamchik/namecase)[![PHP](https://camo.githubusercontent.com/1653948c8d12781e0bdf6282c063e5684f843140b6e0d04f55c1aebf65f55d47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d68747470732533412532462532466769746875622e636f6d25324674616d74616d6368696b2532466e616d65636173652532467261772532466d6173746572253246636f6d706f7365722e6a736f6e2671756572793d2532342e726571756972652e706870267374796c653d666c61742d737175617265266c6162656c3d504850)](https://camo.githubusercontent.com/1653948c8d12781e0bdf6282c063e5684f843140b6e0d04f55c1aebf65f55d47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d68747470732533412532462532466769746875622e636f6d25324674616d74616d6368696b2532466e616d65636173652532467261772532466d6173746572253246636f6d706f7365722e6a736f6e2671756572793d2532342e726571756972652e706870267374796c653d666c61742d737175617265266c6162656c3d504850)[![Total Downloads](https://camo.githubusercontent.com/110a38d8d0983d11bf4924d27f69f24e8cb01d43fe9ff0c7cbac7864bafc497f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74616d74616d6368696b2f6e616d65636173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tamtamchik/namecase)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/5ea424be03605f80f56a939e5580901192eaffdbd0a50a513c50040108de4f15/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f74616d74616d6368696b2f6e616d65636173652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tamtamchik/namecase/code-structure)[![Coverage Status](https://camo.githubusercontent.com/4df1d7fe029dd30da3c15a13ad900c97e1ca63c74b13922bbb8ceef85dde50a2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f74616d74616d6368696b2f6e616d65636173652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tamtamchik/namecase/code-structure)[![Quality Score](https://camo.githubusercontent.com/9e981513657afdaeaa8c6638e73921a619748f6d5e3149c5d5d8cf10a55d6d59/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f74616d74616d6368696b2f6e616d65636173652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tamtamchik/namecase)

[![SensioLabsInsight](https://camo.githubusercontent.com/bbc3aceda97a0e3499e618457a630541cfd5356024b6390eb05608c42bff90c8/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f32396265633866342d616562302d346136322d396332652d3264393361306137316263632f736d616c6c2e737667)](https://insight.symfony.com/projects/29bec8f4-aeb0-4a62-9c2e-2d93a0a71bcc)

Forenames and surnames are often stored either entirely in UPPERCASE or lowercase. This package allows you to convert names into the correct case where possible. Although forenames and surnames are typically stored separately if they appear in a single string, whitespace-separated, NameCase deals correctly with them.

Currently, NameCase correctly name-cases names which include any of the following:

```
Mc, Mac, al, el, ap, bat, ben, bin, binti, binte, da, de, das, dos, delle, della, di, du, del, der, den, ten, ter, la, le, lo, van and von.

```

It correctly deals with names that contain apostrophes and hyphens, too.

Note

This README.md is for version 3.x.
If you need a PHP 5 compatible version, please use 1.0.x! [README.md](https://github.com/tamtamchik/namecase/blob/1.0.x/README.md#namecase)

Install
-------

[](#install)

Via Composer

```
$ composer require tamtamchik/namecase
```

Usage
-----

[](#usage)

```
use \Tamtamchik\NameCase\Formatter;
use function \Tamtamchik\NameCase\str_name_case;

// As a static call
Formatter::nameCase("KEITH");                            // => Keith
Formatter::nameCase("LEIGH-WILLIAMS");                   // => Leigh-Williams
Formatter::nameCase("MCCARTHY");                         // => McCarthy
Formatter::nameCase("O'CALLAGHAN");                      // => O'Callaghan
Formatter::nameCase("ST. JOHN");                         // => St. John
Formatter::nameCase("VON STREIT");                       // => von Streit
Formatter::nameCase("AP LLWYD DAFYDD");                  // => ap Llwyd Dafydd
Formatter::nameCase("HENRY VIII");                       // => Henry VIII
Formatter::nameCase("VAN DYKE");                         // => van Dyke

// Or as an instance
$formatter = new Formatter();
$formatter->nameCase("LOUIS XIV");                       // => Louis XIV

// Or as a function
str_name_case("JJ ABRAMS");                              // => JJ Abrams

// Passing options (see below for details)
Formatter::setOptions([
  'lazy'        => true,
  'irish'       => true,
  'spanish'     => false,
  'roman'       => true,
  'hebrew'      => true,
  'postnominal' => true,
]);

// Or
$formatter = new Formatter(['spanish' => true]);

// Or
$formatter->setOptions([
    'lazy' = false,
    'postnominal' => false
]);

// Or even
Formatter::nameCase("VAN DYKE", ['lazy' = false]);

// And for function
str_name_case("VAN DYKE", ['lazy' = false]);
```

Options
-------

[](#options)

- `lazy` – Default: `true`. Do not do anything if the string is already mixed case and the lazy option is `true`.
- `irish` – Default: `true`. Correct "Mac" exceptions.
- `spanish` – Default: `false`. Correct `el, la` and Spanish conjunctions.
- `roman` – Default: `true`. Correct Roman numbers.
- `hebrew` – Default: `true`. Correct `ben, bat`.
- `postnominal` – Default: `true`. Correct post-nominal e.g. `PhD`.

Exclude Post-Nominals
---------------------

[](#exclude-post-nominals)

```
