PHP code example of lil-pecky / random-person-generator

1. Go to this page and download the library: Download lil-pecky/random-person-generator 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/ */

    

lil-pecky / random-person-generator example snippets


use LilPecky\RandomPersonGenerator\Factory;
use LilPecky\RandomPersonGenerator\Locale;

// the provided locale is 

use LilPecky\RandomPersonGenerator\Factory;

// generator for a completely random locale (en_GB, fr_FR, pt_BR, ...)
$generator = Factory::createWithRandomLocale(); 

// generator for a random locale within a specific language (nl_BE or nl_NL)
$generator = Factory::createWithRandomLocale('nl'); 

LilPecky\RandomPersonGenerator\Languages::LANGUAGES

$locale = Locale::create('nl_NL');
$generator = Factory::create($locale);

$amount = new Amount(10);
$startDate = '2013-01-01';
$endDate = '2023-01-01';
$gender = Gender::FEMALE;

// generates a single Dutch person, with a male given name and date of birth between $startDate and $endDate
$person = $generator->person($startDate, $endDate, $gender);

// generates 10 Dutch people, each with a male given name and date of birth between $startDate and $endDate
$people = $generator->people($amount, $startDate, $endDate, $generator);
$people = $generator->persons($amount, $startDate, $endDate, $generator);



$locale = Locale::create('nl_NL');
$generator = Factory::create($locale);

// generates a random date between two bounds.
// if no start date is provided, it defaults to now - 30 years. Can also be a DateTimeImmutable object
// if no end date is provided, it defaults to now. Can also be a DateTimeImmutable object
$generator->dateBetween('2013-01-01', '2023-01-01');

// generates a random male Dutch given name
// if no gender is provided, it defaults to Gender::MALE 
$generator->givenName(Gender::MALE); 

// generates a random Dutch family name
$generator->familyName();

$locale = Locale::create('is_IS');
$generator = Factory::create($locale);

echo $generator->familyName(Gender::FEMALE);
// Eiðsdóttir

echo $generator->familyName(Gender::MALE);
// Þorfinnsson

php scripts/generate-php-from-json.php

php scripts/generate-json-from-php.php

LilPecky\RandomPersonGenerator\Providers\Name::class

LilPecky\RandomPersonGenerator\Languages::LANGUAGES