PHP code example of wwwd3v / name-parser-and-anonymizer

1. Go to this page and download the library: Download wwwd3v/name-parser-and-anonymizer 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/ */

    

wwwd3v / name-parser-and-anonymizer example snippets


use Wwwd3v\NameParserAndAnonymizer\NameParserAndAnonymizer;

//...

$parser = new NameParserAndAnonymizer();

$name = $parser->parse('John Steinbeck');

$name->getFirstName(); // 'John
$name->getLastName();  // 'Steinbeck'

(string) $name;        // 'John Steinbeck'

$name = $parser->parse('John Steinbeck')->anonymize();

$name->getFirstName(); // 'John
$name->getLastName();  // 'S.'

(string) $name;        // 'John S.'

$name = $parser->parse('John Ronald Reuel Tolkien');

$name->getFirstName();   // 'John
$name->getMiddleNames(); // ['Ronald', 'Reuel']
$name->getLastName();    // 'Tolkien'

(string) $name;        // 'John Ronald Reuel Tolkien'

$name = $parser->parse('John Ronald Reuel Tolkien')->anonymize();

$name->getFirstName();   // 'John
$name->getMiddleNames(); // []
$name->getLastName();    // 'T.'

(string) $name;        // 'John T.'

$name = $parser->parse('John Ronald Reuel Tolkien')->anonymize([
    'middleNames' => 'keep',
]);

(string) $name; // 'John Ronald Reuel T.'

$name = $parser->parse('John Ronald Reuel Tolkien')->anonymize([
    'middleNames' => 'anonymize',
]);

(string) $name; // 'John R. R. T.'

$name = $parser->parse(' John   Ronald    Reuel           Tolkien  ');

$name->getFirstName();   // 'John
$name->getMiddleNames(); // ['Ronald', 'Reuel']
$name->getLastName();    // 'Tolkien'

(string) $name;        // 'John Ronald Reuel Tolkien'