php庫Faker

來源:互聯網
上載者:User

標籤:style   http   color   使用   ar   for   資料   div   sp   

Faker
  • License : MIT
  • Source Code
  • Allo點評:Faker是一個很神奇的項目,會自動產生擬真的資料,包括使用者資料、長文本、IP、日期等等,在網站上線前測試時非常好用。

github地址:

https://github.com/fzaninotto/Faker

基本使用:

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.

<?php// require 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::create();// generate data by accessing propertiesecho $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 (random) result. This is because Faker uses __get() magic, and forwards Faker\Generator->$property calls toFaker\Generator->format($property).

<?phpfor ($i=0; $i < 10; $i++) { echo $faker->name, "\n";}

Formatters

Each of the generator properties (like name, address, and lorem) are called "formatters". A faker generator has many of them, packaged in "providers". Here is 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庫Faker

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.