PHP Library to generate fake name, address, phone number, account details etc.

If you need N number of fake profile data for testing purpose then In this post I am going to share awesome PHP library which generate full fake profile of user which you can use for testing purpose. 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 many more things this fake data fit for you.



Generate N number of fake profiles using PHP

Step:1 First Download Faker PHP librar form gethub.

OR

You can also install faker using composer.

composer require fzaninotto/faker

Step:2 Load faker library where you need to generate fake data.

require_once '/path/to/Faker/src/autoload.php';

Step:3

Use Faker\Factory::create() to create and initialize a faker generator, which can generate data by accessing properties named after the type of data you want.

// use the factory to create a Faker\Generator instance
$faker = Faker\Factory::create();
 
// generate data by accessing properties
echo $faker->name;
  // 'Lucy Cechtelar';
echo $faker->address;

Generate ten random name and address.

for ($i=0; $i < 10; $i++) {
  echo $faker->name.' - '.$faker->address, "\n";
}

Now you have configured Faker and generate N number of fake profile data.

Click Here To see full official API.


Posted in PHP