Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
It's heavily inspired by Perl's Data::Faker, and by Ruby's Faker.
Faker requires PHP >= 7.1.
composer require fakerphp/faker
Full documentation can be found over on fakerphp.github.io.
Use Faker\Factory::create()
to create and initialize a Faker generator, which can generate data by accessing methods named after the type of data you want.
<?php
require_once 'vendor/autoload.php';
// use the factory to create a Faker\Generator instance
$faker = Faker\Factory::create();
// generate data by calling methods
echo $faker->name();
// 'Vince Sporer'
echo $faker->email();
// 'walter.sophia@hotmail.com'
echo $faker->text();
// 'Numquam ut mollitia at consequuntur inventore dolorem.'
Each call to $faker->name()
yields a different (random) result. This is because Faker uses __call()
magic, and forwards Faker\Generator->$method()
calls to Faker\Generator->format($method, $attributes)
.
<?php
for ($i = 0; $i < 3; $i++) {
echo $faker->name() . "\n";
}
// 'Cyrus Boyle'
// 'Alena Cummerata'
// 'Orlo Bergstrom'
Faker is released under the MIT License. See LICENSE
for details.