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 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 Faker\Generator instance
$faker = Faker\Factory::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 Faker\Generator->$property calls toFaker\Generator->format($property).

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

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.

Faker\Provider\Base

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'
 

php库Faker的更多相关文章

  1. python随机生成库faker库api详解

    # -*- coding: utf-8 -*- # @Author : FELIX # @Date : 2018/6/30 9:49 from faker import Factory # zh_CN ...

  2. [转] 前后端分离开发模式的 mock 平台预研

    引入 mock(模拟): 是在项目测试中,对项目外部或不容易获取的对象/接口,用一个虚拟的对象/接口来模拟,以便测试. 背景 前后端分离 前后端仅仅通过异步接口(AJAX/JSONP)来编程 前后端都 ...

  3. 【0】Laravel 5.1 简介

    1.简介 Laravel是一套简洁.优雅的PHP Web开发框架(PHP Web Framework).它可以让你从面条一样杂乱的代码中解脱出来:它可以帮你构建一个完美的网络APP,而且每行代码都可以 ...

  4. python爬取免费优质IP归属地查询接口

    python爬取免费优质IP归属地查询接口 具体不表,我今天要做的工作就是: 需要将数据库中大量ip查询出起归属地 刚开始感觉好简单啊,毕竟只需要从百度找个免费接口然后来个python脚本跑一晚上就o ...

  5. 精选!15 个必备的 VSCode 插件(前端类)

      精选!15 个必备的 VSCode 插件(前端类)   就像大多数 IDE 一样,VSCode 也有一个扩展和主题市场,包含了数以千计质量不同的插件.为了帮助大家挑选出值得下载的插件,我们针对性的 ...

  6. python3爬虫入门程序

    适用于有且只有一点Python3和网页基础的朋友,大牛&路人请绕道 (本文很多废话,第一次在网上长篇大论,所以激动的停不下来,如果有大佬路过,也希望不要直接绕道,烦请指点一二) 感谢博客园给了 ...

  7. 精选!15个必备的VSCode插件

    Visual Studio Code 是由微软开发的一款免费.跨平台的文本编辑器.由于其卓越的性能和丰富的功能,它很快就受到了大家的喜爱. 就像大多数 IDE 一样,VSCode 也有一个扩展和主题市 ...

  8. 自己使用过比较好用的VSCode插件

    C/C++  [ms-vscode.cpptolls]    智能推导,调试和代码浏览 C/C++ Clang Command Adapter [mitaki28.vscode-clang]   使用 ...

  9. [转]精选!15个必备的VSCode插件

    Visual Studio Code 是由微软开发的一款免费.跨平台的文本编辑器.由于其卓越的性能和丰富的功能,它很快就受到了大家的喜爱. 就像大多数 IDE 一样,VSCode 也有一个扩展和主题市 ...

随机推荐

  1. 1066. Root of AVL Tree (25)

    An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...

  2. c语言知识点总结(摘自head first c)

    gcc name.c -o name;   ./name或者gcc name.c -o name &&  ./name;同时执行关键字:void sizeof(运算符,它能告诉你某样东 ...

  3. python之类定义

    <python基础教程>第7章说python中的类定义: 1. 要么声明__metaclass__=type 2. 要么继承object. 但是直接定义下类, 也没报错: >> ...

  4. 【nodejs】关于 alert 和 document

    Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation.保留所有权利. C:\Windows\system32>n ...

  5. CSS3实战之新增的选择器

    用的比较少 看到知道怎么回事就ok http://www.w3.org/TR/css3-selectors/#selectors http://www.cnblogs.com/jscode/archi ...

  6. Linq to XML 之XElement的Descendants方法的新发现

    C#操作XML的方法有很多,但个人认为最方便的莫过于Linq to XML了,特别是XElement的Descendants方法是我最常用的一个方法. 这个方法可以根据节点名(Name)找到当前调用的 ...

  7. 64bit Ubuntu, Android AAPT, R.java

    Ubuntu 13.10 aapt: error while loading shared libraries: libstdc++.so.6: cannot open shared object f ...

  8. c语言编程之队列(链表实现)

    用链表实现了队列,完成了队列的入队和出队功能. #include"stdio.h" typedef int element; typedef struct Node{ struct ...

  9. Python求算数平方根和约数

    一.求算术平方根 a=0 x=int(raw_input('Enter a number:')) if x >= 0: while a*a < x: a = a + 1 if a*a != ...

  10. php中的性能挖掘

    搞php以后,感觉总是很别扭,因为我觉得php会很慢,因为array普遍,在Key的循环查找不是很浪费性能么!因为我以前搞.net和java,他们是用的大多是寻址和索引方式,而php中太多是使用Key ...