PHP Library Faker

Source: Internet
Author: User
Tags autoloader

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.