PHP code example of alistairshaw / name-exploder

1. Go to this page and download the library: Download alistairshaw/name-exploder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alistairshaw / name-exploder example snippets




use AlistairShaw\NameExploder\NameExploder;

// You can get a Name object by passing in the full name
$nameExploder = new NameExploder();
$name = $nameExploder->explode('Mr Alistair Shaw');

// get the pieces back
echo $name->firstName();
echo $name->lastName();
echo $name->title();
echo $name->middleInitial();

// cast the Name object as string to just get full name back
echo $name;

// pass in the language for the titles (default is english)
$nameExploder = new NameExploder('es');
$name = $nameExploder->explode('Mr Alistair Shaw');

// make a name from pieces
$name = $nameExploder->implode('Alistair', 'Shaw', '', 'Mr');

// update the title on a name
$name = $nameExploder->updateTitle('Dr', $name);



use AlistairShaw\NameExploder\NameExploder;

// pass in a custom repository implementation
$nameExploder = new NameExploder('es', new CustomTitleRepository());
$name = $nameExploder->explode('Mr Alistair Shaw');