zoukankan      html  css  js  c++  java
  • php库Faker

    Faker

    • License : MIT
    • Source Code
    • Allo点评:Faker是一个很神奇的项目,会自动生成拟真的数据,包括用户资料、长文本、IP、日期等等,在网站上线前测试时非常好用。

    github地址:

    https://github.com/fzaninotto/Faker

    基本使用:

    Use FakerFactory::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 autoloader
    require_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 FakerGenerator instance
    $faker = FakerFactory::create();
    
    // generate data by accessing properties
    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 (random) result. This is because Faker uses __get() magic, and forwards FakerGenerator->$property calls toFakerGenerator->format($property).

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

    Formatters

    Each of the generator properties (like nameaddress, 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.

    FakerProviderBase

    randomDigit             // 7
    randomDigitNotNull      // 5
    randomNumber($nbDigits = NULL) // 79907610
    randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL) // 48.8932
    numberBetween($min = 1000, $max = 9000) // 8567
    randomLetter            // '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'


     


  • 相关阅读:
    RAID磁盘阵列介绍
    Nginx如何使用Nginx实现MySQL数据库的负载均衡
    挽救数据库性能的30条黄金法则
    mysql主从复制 (指定复制的数库或者表)
    Nginx系列之负载均衡策略
    Redis安装部署(一主二从三哨兵)
    让你的 Linux 命令骚起来
    MySQL/数据库 知识点总结
    Docker私有仓库搭建与界面化管理
    mysql sql语句修改字段名称,字段长度
  • 原文地址:https://www.cnblogs.com/youxin/p/3986771.html
Copyright © 2011-2022 走看看