# Faker
Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
Faker is heavily inspired by Perl's [Data::Faker](http://search.cpan.org/~jasonk/Data-Faker-0.07/), and by ruby's [Faker](https://rubygems.org/gems/faker).
Faker requires PHP >= 5.3.3.
[![Monthly Downloads](https://poser.pugx.org/fzaninotto/faker/d/monthly.png)](https://packagist.org/packages/fzaninotto/faker) [![Build Status](https://secure.travis-ci.org/fzaninotto/Faker.png)](http://travis-ci.org/fzaninotto/Faker) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/eceb78a9-38d4-4ad5-8b6b-b52f323e3549/mini.png)](https://insight.sensiolabs.com/projects/eceb78a9-38d4-4ad5-8b6b-b52f323e3549)
## Installation
```sh
composer require fzaninotto/faker
```
## Basic Usage
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
<?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;
// Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi
// beatae sint laudantium consequatur. Magni occaecati itaque sint et sit tempore. Nesciunt
// amet quidem. Iusto deleniti cum autem ad quia aperiam.
// A consectetur quos aliquam. In iste aliquid et aut similique suscipit. Consequatur qui
// quaerat iste minus hic expedita. Consequuntur error magni et laboriosam. Aut aspernatur
// voluptatem sit aliquam. Dolores voluptatum est.
// Aut molestias et maxime. Fugit autem facilis quos vero. Eius quibusdam possimus est.
// Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati.
// Et sint et. Ut ducimus quod nemo ab voluptatum.
```
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 to `Faker\Generator->format($property)`.
```php
<?php
for ($i=0; $i < 10; $i++) {
echo $faker->name, "\n";
}
// Adaline Reichel
// Dr. Santa Prosacco DVM
// Noemy Vandervort V
// Lexi O'Conner
// Gracie Weber
// Roscoe Johns
// Emmett Lebsack
// Keegan Thiel
// Wellington Koelpin II
// Ms. Karley Kiehn V
```
**Tip**: For a quick generation of fake data, you can also use Faker as a command line tool thanks to [faker-cli](https://github.com/bit3/faker-cli).
## 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 // 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'
shuffle('hello, world') // 'rlo,h eoldlw'
shuffle(array(1, 2, 3)) // array(2, 1, 3)
numerify('Hello ###') // 'Hello 609'
lexify('Hello ???') // 'Hello wgt'
bothify('Hello ##??') // 'Hello 42jz'
asciify('Hello ***') // 'Hello R6+'
regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej
### `Faker\Provider\Lorem`
word // 'aut'
words($nb = 3) // array('porro', 'sed', 'magni')
sentence($nbWords = 6) // 'Sit vitae voluptas sint non voluptates.'
sentences($nb = 3) // array('Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.')
paragraph($nbSentences = 3) // 'Ut ab voluptas sed a nam. Sint autem inventore aut officia aut aut blanditiis. Ducimus eos odit amet et est ut eum.'
paragraphs($nb = 3) // array('Quidem ut sunt et quidem est accusamus aut. Fuga est placeat rerum ut. Enim ex eveniet facere sunt.', 'Aut nam et eum architecto fugit repellendus illo. Qui ex esse veritatis.', 'Possimus omnis aut incidunt sunt. Asperiores incidunt iure sequi cum culpa rem. Rerum exercitationem est rem.')
text($maxNbChars = 200) // 'Fuga totam reiciendis qui architecto fugiat nemo. Consequatur recusandae qui cupiditate eos quod.'
### `Faker\Provider\en_US\Person`
title($gender = null|'male'|'female') // 'Ms.'
titleMale // 'Mr.'
titleFemale // 'Ms.'
suffix // 'Jr.'
name($gender = null|'male'|'female') // 'Dr. Zane Stroman'
firstName($gender = null|'male'|'female') // 'Maynard'
firstNameMale // 'Maynard'
firstNameFemale // 'Rachel'
lastName // 'Zulauf'
### `Faker\Provider\en_US\Address`
cityPrefix // 'Lake'
secondaryAddress // 'Suite 961'
state // 'NewMexico'
stateAbbr // 'OH'
citySuffix // 'borough'
streetSuffix // 'Keys'
buildingNumber // '484'
city // 'West Judge'
streetName // 'Keegan Trail'
streetAddress // '439 Karley Loaf Suite 897'
postcode // '17916'
address // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
country // 'Falkland Islands (Malvinas)'
latitude // 77.147489
longitude // 86.211205
### `Faker\Provider\en_US\PhoneNumber`
phoneNumber // '132-149-0269x3767'
### `Faker\Provider\en_US\Company`
catchPhrase // 'Monitored regional contingency'
bs // 'e-enable robust architectures'
company // 'Bogan-Treutel'
companySuffix // 'and Sons'
### `Faker\Provider\en_US\Text`
realText($maxNbChars = 200, $indexSize = 2) // "And yet I wish you could manage it?) 'And what are they made of?' Alice asked in a shrill, passionate voice. 'Would YOU like cats if you were never even spoke to Time!' 'Perhaps not,' Alice replied."
### `Faker\Provider\DateTime`
unixTime($max = 'now') // 58781813
dateTime($max = 'now') // DateTime('2008-04-25 08:37:17')
dateTimeAD($max = 'now') // DateTime('1800-04-29 20:38:49')
iso8601($max = 'now') // '1978-12-09T10:10:29+0000'
date($format = 'Y-m-d', $max = 'now') // '1979-06-09'
time($format = 'H:i:s', $max = 'now') // '20:49:42'
dateTimeBetween($startDate = '-30 years', $endDate = 'now') // DateTime('2003-03-15 02:00:49')
dateTimeThisCentury($max = 'now') // DateTime('1915-05-30 19:28:21')
dateTimeThisDecade($max = 'now') // DateTime('2007-05-29 22:30:48')
dateTimeThisYear($max = 'now') // DateTime('2011-02-27 20:52:14')
dateTimeThisMonth($max = 'now') // DateTime('2011-10-23 13:46:23')
amPm($max = 'now') // 'pm'
dayOfMonth($max = 'now') // '04'
dayOfWeek($max = 'now') // 'Friday'
month($max = 'now') // '06'
monthName($max = 'now') // 'January'
year($max = 'now') // '1993'
cen
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
PHP和MySQLweb开发第5版 PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快。
资源推荐
资源详情
资源评论
收起资源包目录
PHP和MySQLweb开发第5版(英文高清PDF和31章源码) (5270个子文件)
a 0B
a3fcf830293d2e5529946840f9589c31045c5185 393B
url_matcher1.apache 6KB
url_matcher2.apache 184B
artisan 2KB
build 94B
build-manual 8KB
build-phar 958B
build-vendor 190B
symfony_debug.c 7KB
CHANGES 6KB
web.config 907B
a.dat.copy 0B
ab.dat.copy 0B
abc.dat.copy 0B
ca.crt 1KB
sign2.crt 1KB
intermediate.crt 1KB
encrypt2.crt 1KB
encrypt.crt 1KB
sign.crt 1KB
bootstrap.min.css 115KB
nv.d3.min.css 9KB
style.css 2KB
styles.css 2KB
styles.css 2KB
app.css 577B
resources.csv 96B
valid.csv 36B
empty.csv 0B
resources.dat 352B
resources.dat 3B
bar.dat 0B
a.dat 0B
abc.dat 0B
ab.dat 0B
smoke.conf.php.default 2KB
acceptance.conf.php.default 1KB
dashboard.html.dist 7KB
file.html.dist 3KB
TestCaseMethod.tpl.dist 2KB
directory.html.dist 2KB
phpunit.xml.dist 1KB
phpunit.xml.dist 1KB
phpunit.xml.dist 1KB
phpmd.xml.dist 1KB
phpunit.xml.dist 1KB
mocked_class.tpl.dist 1KB
phpunit.xml.dist 930B
phpunit.xml.dist 904B
file_item.html.dist 871B
phpunit.xml.dist 835B
phpunit.xml.dist 834B
phpunit.xml.dist 831B
phpunit.xml.dist 830B
phpunit.xml.dist 829B
phpunit.xml.dist 827B
phpunit.xml.dist 821B
directory_item.html.dist 821B
phpunit.xml.dist 780B
phpunit.xml.dist 776B
phpunit.xml.dist 776B
phpunit.xml.dist 775B
phpunit.xml.dist 773B
proxied_method.tpl.dist 716B
phpunit.xml.dist 694B
phpunit.xml.dist 681B
phpunit.xml.dist 677B
phpunit.xml.dist 661B
phpunit.xml.dist 658B
phpunit.xml.dist 654B
phpunit.xml.dist 648B
mocked_method.tpl.dist 644B
phpunit.xml.dist 635B
method_item.html.dist 632B
phpunit.xml.dist 619B
phpunit.xml.dist 616B
phpunit.xml.dist 615B
phpdox.xml.dist 584B
phpunit.xml.dist 531B
phpunit.xml.dist 460B
phpunit.xml.dist 372B
phpunit.xml.dist 319B
coverage_bar.html.dist 305B
phpunit.xml.dist 242B
mocked_class_method.tpl.dist 237B
wsdl_class.tpl.dist 179B
unmocked_clone.tpl.dist 159B
mocked_static_method.tpl.dist 151B
mocked_clone.tpl.dist 132B
wsdl_method.tpl.dist 60B
trait_class.tpl.dist 55B
.editorconfig 234B
.editorconfig 188B
.empty 0B
glyphicons-halflings-regular.eot 20KB
aws_assign_ip.erb 986B
vhost.conf.erb 797B
other-file.example 0B
Exception class 1KB
共 5270 条
- 1
- 2
- 3
- 4
- 5
- 6
- 53
资源评论
nakata_com
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- tomcat6.0配置oracle数据库连接池中文WORD版最新版本
- hibernate连接oracle数据库中文WORD版最新版本
- MyEclipse连接MySQL的方法中文WORD版最新版本
- MyEclipse中配置Hibernate连接Oracle中文WORD版最新版本
- MyEclipseTomcatMySQL的环境搭建中文WORD版3.37MB最新版本
- hggm - 国密算法 SM2 SM3 SM4 SM9 ZUC Python实现完整代码-算法实现资源
- SQLITE操作入门中文WORD版最新版本
- Sqlite操作实例中文WORD版最新版本
- SQLITE特性分析中文WORD版最新版本
- ORACLE创建表空间中文WORD版最新版本
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功