Faker
- License:mit
- Source Code
- Allo Reviews: Faker is a magical project that automatically generates quasi-true data, including user profiles, long texts, IP, dates, and more, and is very useful when testing a website before it goes online.
GitHub Address:
Https://github.com/fzaninotto/Faker
Basic use:
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.
<?PhpRequire the Faker AutoloaderRequire_once'/path/to/faker/src/autoload.php ';Alternatively, use another PSR-0 compliant autoloader (like the Symfony2 ClassLoader for instance)//use the factory to create a faker\generator instance $faker = faker\factory :: creat e (); echo $faker ->name//' Lucy cechtelar '; echo $faker ->address //"426 Jordy Lodge //Cartwrightshire, SC 88120-6700" echo $faker ->text
Even if this example shows a property access, each call to $faker->name
yields a different (r Andom) result. This is because Faker uses __get ()
magic, and forwards faker\generator->$ Property
calls to Faker\generator->format ($property)
.
<? php($i=0$i+ +$faker name"\ n";}
Formatters
Each of the generator properties (like name
, address
, and lorem
) is called "formatters". A Faker Generator have many of them, packaged in "providers". A list of the bundled formatters in the default locale.
Faker\Provider\Base
randomDigit // 7randomDigitNotNull // 5randomNumber($nbDigits = NULL) // 79907610randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL) // 48.8932numberBetween($min = 1000, $max = 9000) // 8567randomLetter // ‘b‘randomElements($array = array (‘a‘,‘b‘,‘c‘), $count = 1) // array(‘c‘)randomElement($array = array (‘a‘,‘b‘,‘c‘)) // ‘b‘numerify($string = ‘###‘) // ‘609‘lexify($string = ‘????‘) // ‘wgts‘bothify($string = ‘## ??‘) // ‘42 jz‘
PHP Library Faker