Laravel 填充數據Faker

https://github.com/fzaninotto/Faker

Skip to content

This repository

Pull requests

Issues

Gist

Watch422

Star7,892

Fork

1,192

fzaninotto/Faker

CodeIssues12Pull requests23PulseGraphs

Faker is a PHP library that generates fake data for you

1,579commits

5branches

6releases

228contributors

PHP100.0%

PHP

New file

Upload filesFind file

HTTPS

Download ZIP

Branch:master

New pull request

Latest commit66ea6b02 days agofzaninottoMerge pull request#696from chanmix51/patch-1

File uploading is now available

You can now drag and drop files into your repositories.Learn more

Dismiss

srcadded Japanese text for realText.2 days ago

testMerge pull request#763from mikk150/master2 days ago

.gitignoreCorrected .gitignorea year ago

.travis.ymlEnhancement: Cache dependencies installed with Composer between builds7 months ago

CHANGELOG.mdUpdate 1.5 release date9 months ago

CONTRIBUTING.mdUpdate CONTRIBUTING.md7 months ago

LICENSEEnsured files end in a single new line2 years ago

MakefileFix: Dev dependencies are installed by default7 months ago

composer.jsonMerge pull request#663from localheinz/fix/autoload-dev2 days ago

phpunit.xml.distEnhancement: Use colors option when running phpunit7 months ago

readme.mdMerge pull request#696from chanmix51/patch-12 days ago

readme.md

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'sData::Faker, and by ruby'sFaker.

Faker requires PHP >= 5.3.3.

Table of Contents

Installation

Basic Usage

Formatters

Base

Lorem Ipsum Text

Person

Address

Phone Number

Company

Real Text

Date and Time

Internet

User Agent

Payment

Color

File

Image

Uuid

Barcode

Miscellaneous

Biased

Modifiers

Localization

Populating Entities Using an ORM or an ODM

Seeding the Generator

Faker Internals: Understanding Providers

Real Life Usage

Language specific formatters

Third-Party Libraries Extending/Based On Faker

License

Installation

composer require fzaninotto/faker

Basic Usage

UseFaker\Factory::create()to create and initialize a faker generator, which can generate data by accessing properties named after the type of data you want.

name;// 'Lucy Cechtelar';echo$faker->address;// "426 Jordy Lodge// Cartwrightshire, SC 88120-6700"echo$faker->text;// Dolores sit sint laboriosam dolorem culpa et autem. Beatae nam sunt fugit// et sit et mollitia sed.// Fuga deserunt tempora facere magni omnis. Omnis quia temporibus laudantium// sit minima sint.

Even if this example shows a property access, each call to$faker->nameyields a different (random) result. This is because Faker uses__get()magic, and forwardsFaker\Generator->$propertycalls toFaker\Generator->format($property).

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 tofaker-cli.

Formatters

Each of the generator properties (likename,address, andlorem) 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, $asText = false)? ? ? ? ? ? ? ? ? // array('porro', 'sed', 'magni')

sentence($nbWords = 6, $variableNbWords = true)? // 'Sit vitae voluptas sint non voluptates.'

sentences($nb = 3, $asText = false)? ? ? ? ? ? ? // array('Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.')

paragraph($nbSentences = 3, $variableNbSentences = true) // '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, $asText = false)? ? ? ? ? ? // 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($min = -90, $max = 90)? ? // 77.147489

longitude($min = -180, $max = 180)? // 86.211205

Faker\Provider\en_US\PhoneNumber

phoneNumber? ? ? ? ? ? // '201-886-0269 x3767'

tollFreePhoneNumber? ? // '(888) 937-7238'

Faker\Provider\en_US\Company

catchPhrase? ? ? ? ? ? // 'Monitored regional contingency'

bs? ? ? ? ? ? ? ? ? ? ? // 'e-enable robust architectures'

company? ? ? ? ? ? ? ? // 'Bogan-Treutel'

companySuffix? ? ? ? ? // 'and Sons'

jobTitle? ? ? ? ? ? ? ? // 'Cashier'

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')

dateTimeInInterval($startDate = '-30 years', $interval = '+ 5 days') // 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'

century? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 'VI'

timezone? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 'Europe/Paris'

Faker\Provider\Internet

email? ? ? ? ? ? ? ? ? // 'tkshlerin@collins.com'

safeEmail? ? ? ? ? ? ? // 'king.alford@example.org'

freeEmail? ? ? ? ? ? ? // 'bradley72@gmail.com'

companyEmail? ? ? ? ? ? // 'russel.durward@mcdermott.org'

freeEmailDomain? ? ? ? // 'yahoo.com'

safeEmailDomain? ? ? ? // 'example.org'

userName? ? ? ? ? ? ? ? // 'wade55'

password? ? ? ? ? ? ? ? // 'k&|X+a45*2['

domainName? ? ? ? ? ? ? // 'wolffdeckow.net'

domainWord? ? ? ? ? ? ? // 'feeney'

tld? ? ? ? ? ? ? ? ? ? // 'biz'

url? ? ? ? ? ? ? ? ? ? // 'http://www.skilesdonnelly.biz/aut-accusantium-ut-architecto-sit-et.html'

slug? ? ? ? ? ? ? ? ? ? // 'aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum'

ipv4? ? ? ? ? ? ? ? ? ? // '109.133.32.252'

localIpv4? ? ? ? ? ? ? // '10.242.58.8'

ipv6? ? ? ? ? ? ? ? ? ? // '8e65:933d:22ee:a232:f1c1:2741:1f10:117c'

macAddress? ? ? ? ? ? ? // '43:85:B7:08:10:CA'

Faker\Provider\UserAgent

userAgent? ? ? ? ? ? ? // 'Mozilla/5.0 (Windows CE) AppleWebKit/5350 (KHTML, like Gecko) Chrome/13.0.888.0 Safari/5350'

chrome? ? ? ? ? ? ? ? // 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5) AppleWebKit/5312 (KHTML, like Gecko) Chrome/14.0.894.0 Safari/5312'

firefox? ? ? ? ? ? ? ? // 'Mozilla/5.0 (X11; Linuxi686; rv:7.0) Gecko/20101231 Firefox/3.6'

safari? ? ? ? ? ? ? ? // 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_7_1 rv:3.0; en-US) AppleWebKit/534.11.3 (KHTML, like Gecko) Version/4.0 Safari/534.11.3'

opera? ? ? ? ? ? ? ? ? // 'Opera/8.25 (Windows NT 5.1; en-US) Presto/2.9.188 Version/10.00'

internetExplorer? ? ? // 'Mozilla/5.0 (compatible; MSIE 7.0; Windows 98; Win 9x 4.90; Trident/3.0)'

Faker\Provider\Payment

creditCardType? ? ? ? ? // 'MasterCard'

creditCardNumber? ? ? ? // '4485480221084675'

creditCardExpirationDate // 04/13

creditCardExpirationDateString // '04/13'

creditCardDetails? ? ? // array('MasterCard', '4485480221084675', 'Aleksander Nowak', '04/13')

// Generates a random IBAN. Set $countryCode to null for a random country

iban($countryCode)? ? ? // 'IT31A8497112740YZ575DJ28BP4'

swiftBicNumber? ? ? ? ? // 'RZTIAT22263'

Faker\Provider\Color

hexcolor? ? ? ? ? ? ? // '#fa3cc2'

rgbcolor? ? ? ? ? ? ? // '0,255,122'

rgbColorAsArray? ? ? ? // array(0,255,122)

rgbCssColor? ? ? ? ? ? // 'rgb(0,255,122)'

safeColorName? ? ? ? ? // 'fuchsia'

colorName? ? ? ? ? ? ? // 'Gainsbor'

Faker\Provider\File

fileExtension? ? ? ? ? // 'avi'

mimeType? ? ? ? ? ? ? // 'video/x-msvideo'

// Copy a random file from the source to the target directory and returns the fullpath or filename

file($sourceDir = '/tmp', $targetDir = '/tmp') // '/path/to/targetDir/13b73edae8443990be1aa8f1a483bc27.jpg'

file($sourceDir, $targetDir, false) // '13b73edae8443990be1aa8f1a483bc27.jpg'

Faker\Provider\Image

// Image generation provided by LoremPixel (http://lorempixel.com/)

imageUrl($width = 640, $height = 480) // 'http://lorempixel.com/640/480/'

imageUrl($width, $height, 'cats')? ? // 'http://lorempixel.com/800/600/cats/'

imageUrl($width, $height, 'cats', true, 'Faker') // 'http://lorempixel.com/800/400/cats/Faker'

image($dir = '/tmp', $width = 640, $height = 480) // '/tmp/13b73edae8443990be1aa8f1a483bc27.jpg'

image($dir, $width, $height, 'cats')? // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat!

image($dir, $width, $height, 'cats', true, 'Faker') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat with Faker text

Faker\Provider\Uuid

uuid? ? ? ? ? ? ? ? ? // '7e57d004-2b97-0e7a-b45f-5387367791cd'

Faker\Provider\Barcode

ean13? ? ? ? ? // '4006381333931'

ean8? ? ? ? ? // '73513537'

isbn13? ? ? ? // '9790404436093'

isbn10? ? ? ? // '4881416324'

Faker\Provider\Miscellaneous

boolean($chanceOfGettingTrue = 50) // true

md5? ? ? ? ? // 'de99a620c50f2990e87144735cd357e7'

sha1? ? ? ? ? // 'f08e7f04ca1a413807ebc47551a40a20a0b4de5c'

sha256? ? ? ? // '0061e4c60dac5c1d82db0135a42e00c89ae3a333e7c26485321f24348c7e98a5'

locale? ? ? ? // en_UK

countryCode? // UK

languageCode? // en

currencyCode? // EUR

Faker\Provider\Biased

// get a random number between 10 and 20,

// with more chances to be close to 20

biasedNumberBetween($min = 10, $max = 20, $function = 'sqrt')

Modifiers

Faker provides three special providers,unique(),optional(), andvalid(), to be called before any provider.

// unique() forces providers to return unique values$values=array();for($i=0;$i<10;$i++) {// get a random digit, but always a new one, to avoid duplicates$values[]=$faker->unique()->randomDigit;}print_r($values);// [4, 1, 8, 5, 0, 2, 6, 9, 7, 3]// providers with a limited range will throw an exception when no new unique value can be generated$values=array();try{for($i=0;$i<10;$i++) {$values[]=$faker->unique()->randomDigitNotNull;}}catch(\OverflowException$e) {echo"There are only 9 unique digits not null, Faker can't generate 10 of them!";}// you can reset the unique modifier for all providers by passing true as first argument$faker->unique($reset=true)->randomDigitNotNull;// will not throw OverflowException since unique() was reset// tip: unique() keeps one array of values per provider// optional() sometimes bypasses the provider to return a default value instead (which defaults to NULL)$values=array();for($i=0;$i<10;$i++) {// get a random digit, but also null sometimes$values[]=$faker->optional()->randomDigit;}print_r($values);// [1, 4, null, 9, 5, null, null, 4, 6, null]// optional() accepts a weight argument to specify the probability of receiving the default value.// 0 will always return the default value; 1 will always return the provider. Default weight is 0.5 (50% chance).$faker->optional($weight=0.1)->randomDigit;// 90% chance of NULL$faker->optional($weight=0.9)->randomDigit;// 10% chance of NULL// optional() accepts a default argument to specify the default value to return.// Defaults to NULL.$faker->optional($weight=0.5,$default=false)->randomDigit;// 50% chance of FALSE$faker->optional($weight=0.9,$default='abc')->word;// 10% chance of 'abc'// valid() only accepts valid values according to the passed validator functions$values=array();$evenValidator=function($digit) {return$digit%2===0;};for($i=0;$i<10;$i++) {$values[]=$faker->valid($evenValidator)->randomDigit;}print_r($values);// [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]// just like unique(), valid() throws an overflow exception when it can't generate a valid value$values=array();try{$faker->valid($evenValidator)->randomElement(1,3,5,7,9);}catch(\OverflowException$e) {echo"Can't pick an even number in that set!";}

Localization

Faker\Factorycan take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale (en_EN).

name,"\n";}// Luce du Coulon// Auguste Dupont// Roger Le Voisin// Alexandre Lacroix// Jacques Humbert-Roy// Thérèse Guillet-Andre// Gilles Gros-Bodin// Amélie Pires// Marcel Laporte// Geneviève Marchal

You can check available Faker locales in the source code,under theProviderdirectory. The localization of Faker is an ongoing process, for which we need your help. Don't hesitate to create localized providers to your own locale and submit a PR!

Populating Entities Using an ORM or an ODM

Faker provides adapters for Object-Relational and Object-Document Mappers (currently,Propel,Doctrine2,CakePHP,Spot2andMandangoare supported). These adapters ease the population of databases through the Entity classes provided by an ORM library (or the population of document stores using Document classes provided by an ODM library).

To populate entities, create a new populator class (using a generator instance as parameter), then list the class and number of all the entities that must be generated. To launch the actual data population, call theexecute()method.

Here is an example showing how to populate 5Authorand 10Bookobjects:

addEntity('Author',5);$populator->addEntity('Book',10);$insertedPKs=$populator->execute();

The populator uses name and column type guessers to populate each column with relevant data. For instance, Faker populates a column namedfirst_nameusing thefirstNameformatter, and a column with aTIMESTAMPtype using thedateTimeformatter. The resulting entities are therefore coherent. If Faker misinterprets a column name, you can still specify a custom closure to be used for populating a particular column, using the third argument toaddEntity():

addEntity('Book',5,array('ISBN'=>function()use($generator) {return$generator->ean13(); }));

In this example, Faker will guess a formatter for all columns exceptISBN, for which the given anonymous function will be used.

Tip: To ignore some columns, specifynullfor the column names in the third argument ofaddEntity(). This is usually necessary for columns added by a behavior:

addEntity('Book',5,array('CreatedAt'=>null,'UpdatedAt'=>null,));

Of course, Faker does not populate autoincremented primary keys. In addition,Faker\ORM\Propel\Populator::execute()returns the list of inserted PKs, indexed by class:

(34, 35, 36, 37, 38),//? 'Book'? => (456, 457, 458, 459, 470, 471, 472, 473, 474, 475)// )

In the previous example, theBookandAuthormodels share a relationship. SinceAuthorentities are populated first, Faker is smart enough to relate the populatedBookentities to one of the populatedAuthorentities.

Lastly, if you want to execute an arbitrary function on an entity before insertion, use the fourth argument of theaddEntity()method:

addEntity('Book',5,array(),array(function($book) {$book->publish(); },));

Seeding the Generator

You may want to get always the same generated data - for instance when using Faker for unit testing purposes. The generator offers aseed()method, which seeds the random number generator. Calling the same script twice with the same seed produces the same results.

seed(1234);echo$faker->name;// 'Jess Mraz I';

Tip: DateTime formatters won't reproduce the same fake data if you don't fix the$maxvalue:

dateTime();// equivalent to $faker->dateTime($max = 'now')// make sure you fix the $max parameter$faker->dateTime('2014-02-25 08:37:17');// will return always the same date when seeded

Tip: Formatters won't reproduce the same fake data if you use therand()php function. Use$fakerormt_rand()instead:

realText(rand(10,20));// good$faker->realText($faker->numberBetween(10,20));

Faker Internals: Understanding Providers

AFaker\Generatoralone can't do much generation. It needsFaker\Providerobjects to delegate the data generation to them.Faker\Factory::create()actually creates aFaker\Generatorbundled with the default providers. Here is what happens under the hood:

addProvider(newFaker\Provider\en_US\Person($faker));$faker->addProvider(newFaker\Provider\en_US\Address($faker));$faker->addProvider(newFaker\Provider\en_US\PhoneNumber($faker));$faker->addProvider(newFaker\Provider\en_US\Company($faker));$faker->addProvider(newFaker\Provider\Lorem($faker));$faker->addProvider(newFaker\Provider\Internet($faker));

Whenever you try to access a property on the$fakerobject, the generator looks for a method with the same name in all the providers attached to it. For instance, calling$faker->nametriggers a call toFaker\Provider\Person::name(). And since Faker starts with the last provider, you can easily override existing formatters: just add a provider containing methods named after the formatters you want to override.

That means that you can easily add your own providers to aFaker\Generatorinstance. A provider is usually a class extending\Faker\Provider\Base. This parent class allows you to use methods likelexify()orrandomNumber(); it also gives you access to formatters of other providers, through the protected$generatorproperty. The new formatters are the public methods of the provider class.

Here is an example provider for populating Book data:

generator->sentence($nbWords);returnsubstr($sentence,0,strlen($sentence)-1);}publicfunctionISBN(){return$this->generator->ean13();}}

To register this provider, just add a new instance of\Faker\Provider\Bookto an existing generator:

addProvider(new\Faker\Provider\Book($faker));

Now you can use the two new formatters like any other Faker formatter:

setTitle($faker->title);$book->setISBN($faker->ISBN);$book->setSummary($faker->text);$book->setPrice($faker->randomNumber(2));

Tip: A provider can also be a Plain Old PHP Object. In that case, all the public methods of the provider become available to the generator.

Real Life Usage

The following script generates a valid XML document:

firstName?>"lastName="lastName?>"email="email?>"/>? ? phoneNumber?>"/>boolean(25)):?>dateTimeThisCentury->format('Y-m-d')?>"place="city?>"/>? ? ? streetAddress?>? ? ? city?>? ? ? postcode?>? ? ? state?>? ? ? ? company?>"catchPhrase="catchPhrase?>">boolean(33)):?>bs?>boolean(33)):?>name?>"/>boolean(15)):?>text(400)?>]]>? ?

Running this script produces a document looking like:

? ? ? ? ? ? ? ? 182 Harrison Cove? ? ? North Lloyd? ? ? 45577? ? ? Alabama? ? ? ? ? ? ? orchestrate compelling web-readiness? ? ? ? ? ? ? ? ? ? ? ? ? 90111 Hegmann Inlet? ? ? South Geovanymouth? ? ? 69961-9311? ? ? Colorado? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 9791 Nona Corner? ? ? Harberhaven? ? ? 74062-8191? ? ? RhodeIsland? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 11161 Schultz Via? ? ? Feilstad? ? ? 98019? ? ? NewJersey? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 6106 Nader Village Suite 753? ? ? McLaughlinstad? ? ? 43189-8621? ? ? Missouri? ? ? ? ? ? ? expedite viral synergies? ? ? ? ? ? ? ? ? ? ? ? ? ? 7546 Kuvalis Plaza? ? ? South Wilfrid? ? ? 77069? ? ? Georgia? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 478 Daisha Landing Apt. 510? ? ? West Lizethhaven? ? ? 30566-5362? ? ? WestVirginia? ? ? ? ? ? ? orchestrate dynamic networks? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1251 Koelpin Mission? ? ? North Revastad? ? ? 81620? ? ? Maryland? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 6396 Langworth Hills Apt. 446? ? ? New Carlos? ? ? 89399-0268? ? ? Wyoming? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2246 Kreiger Station Apt. 291? ? ? Kaydenmouth? ? ? 11397-1072? ? ? Wyoming? ? ? ? ? ? ? grow sticky portals? ? ? ? ?

Language specific formatters

Faker\Provider\ar_SA\Person

idNumber;// ID numberecho$faker->nationalIdNumber// Citizen ID numberecho$faker->foreignerIdNumber// Foreigner ID number

Faker\Provider\at_AT\Payment

vat;// "AT U12345678" - Austrian Value Added Tax numberecho$faker->vat(false);// "ATU12345678" - unspaced Austrian Value Added Tax number

Faker\Provider\be_BE\Payment

vat;// "BE 0123456789" - Belgian Value Added Tax numberecho$faker->vat(false);// "BE0123456789" - unspaced Belgian Value Added Tax number

Faker\Provider\bg_BG\Payment

vat;// "BG 0123456789" - Bulgarian Value Added Tax numberecho$faker->vat(false);// "BG0123456789" - unspaced Bulgarian Value Added Tax number

Faker\Provider\cs_CZ\Address

region;// "Liberecky kraj"

Faker\Provider\cs_CZ\Company

ico;// "69663963"

Faker\Provider\cs_CZ\DateTime

monthNameGenitive;// "prosince"echo$faker->formattedDate;// "12. listopadu 2015"

Faker\Provider\cs_CZ\Person

birthNumber;// "7304243452"

Faker\Provider\da_DK\Person

cpr;// "051280-2387"

Faker\Provider\da_DK\Address

kommune;// "Frederiksberg"http:// Generates a random region nameecho$faker->region;// "Region Sj?lland"

Faker\Provider\da_DK\Company

cvr;// "32458723"http:// Generates a random P numberecho$faker->p;// "5398237590"

Faker\Provider\en_NZ\Phone

cellNumber;// "021 123 4567"http:// Generates a toll free numberecho$faker->tollFreeNumber;// "0800 123 456"http:// Area Codeecho$faker->areaCode;// "03"

Faker\Provider\en_US\Payment

bankAccountNumber;// '51915734310'echo$faker->bankRoutingNumber;// '212240302'

Faker\Provider\en_ZA\Company

companyNumber;// 1999/789634/01

Faker\Provider\en_ZA\PhoneNumber

tollFreeNumber;// 0800 555 5555// Generates a mobile phone numberecho$faker->mobileNumber;// 082 123 5555

Faker\Provider\es_ES\Person

dni;// '77446565E'

Faker\Provider\fr_FR\Address

departmentName;// "Haut-Rhin"http:// Generates a random department numberecho$faker->departmentNumber;// "2B"http:// Generates a random department info (department number => department name)$faker->department;// array('18' => 'Cher');// Generates a random regionecho$faker->region;// "Saint-Pierre-et-Miquelon"

Faker\Provider\fr_FR\Company

siren;// 082 250 104// Generates a random SIRET numberecho$faker->siret;// 347 355 708 00224

Faker\Provider\hu_HU\Payment

bankAccountNumber;// "HU09904437680048220079300783"

Faker\Provider\it_IT\Company

vatId();// "IT98746784967"

Faker\Provider\it_IT\Person

taxId();// "DIXDPZ44E08F367A"

Faker\Provider\ja_JP\Person

kanaName;// "アオタ ミノル"http:// Generates a 'kana' first nameecho$faker->firstKanaName;// "ハルカ"http:// Generates a 'kana' last nameecho$faker->lastKanaName;// "ナカジマ"

Faker\Provider\ka_GE\Payment

bankAccountNumber;// "GE33ZV9773853617253389"

Faker\Provider\kk_KZ\Company

businessIdentificationNumber;// "150140000019"

Faker\Provider\kk_KZ\Payment

bank;// "?азкоммерцбанк"http:// Generates a random bank account numberecho$faker->bankAccountNumber;// "KZ1076321LO4H6X41I37"

Faker\Provider\kk_KZ\Person

individualIdentificationNumber;// "780322300455"

Faker\Provider\ko_KR\Address

metropolitanCity;// "?????"http:// Generates a boroughecho$faker->borough;// "???"

Faker\Provider\lv_LV\Person

personalIdentityNumber;// "140190-12301"

Faker\Provider\ne_NP\Address

district;//Generates a Nepali city nameecho$faker->cityName;

Faker\Provider\no_NO\Payment

bankAccountNumber;// "NO3246764709816"

Faker\Provider\pl_PL\Person

pesel;// "40061451555"http:// Generates a random personal identity card numberecho$faker->personalIdentityNumber;// "AKX383360"http:// Generates a random taxpayer identification number (NIP)echo$faker->taxpayerIdentificationNumber;// '8211575109'

Faker\Provider\pl_PL\Company

regon;// "714676680"http:// Generates a random local REGON numberecho$faker->regonLocal;// "15346111382836"

Faker\Provider\pl_PL\Payment

bank;// "Narodowy Bank Polski"http:// Generates a random bank account numberecho$faker->bankAccountNumber;// "PL14968907563953822118075816"

Faker\Provider\pt_PT\Person

taxpayerIdentificationNumber;// '165249277'

Faker\Provider\pt_BR\Address

region;// 'Nordeste'// Generates a random region abbreviationecho$faker->regionAbbr;// 'NE'

Faker\Provider\pt_BR\PhoneNumber

areaCode;// 21echo$faker->cellphone;// 9432-5656echo$faker->landline;// 2654-3445echo$faker->phone;// random landline, 8-digit or 9-digit cellphone number// Using the phone functions with a false argument returns unformatted numbersecho$faker->cellphone(false);// 74336667// cellphone() has a special second argument to add the 9th digit. Ignored if generated a Radio numberecho$faker->cellphone(true,true);// 98983-3945 or 7343-1290// Using the "Number" suffix adds area code to the phoneecho$faker->cellphoneNumber;// (11) 98309-2935echo$faker->landlineNumber(false);// 3522835934echo$faker->phoneNumber;// formatted, random landline or cellphone (obbeying the 9th digit rule)echo$faker->phoneNumberCleared;// not formatted, random landline or cellphone (obbeying the 9th digit rule)

Faker\Provider\pt_BR\Person

name;// 'Sr. Luis Adriano Sepúlveda Filho'// Valid document generators have a boolean argument to remove formattingecho$faker->cpf;// '145.343.345-76'echo$faker->cpf(false);// '45623467866'echo$faker->rg;// '84.405.736-3'echo$faker->cnpj;// '23.663.478/0001-24'

Faker\Provider\ro_MD\Payment

bankAccountNumber;// "MD83BQW1CKMUW34HBESDP3A8"

Faker\Provider\ro_RO\Payment

bankAccountNumber;// "RO55WRJE3OE8X3YQI7J26U1E"

Faker\Provider\ro_RO\Person

prefixMale;// "ing."http:// Generates a random female name prefix/titleecho$faker->prefixFemale;// "d-na."http:// Generates a random male fist nameecho$faker->firstNameMale;// "Adrian"http:// Generates a random female fist nameecho$faker->firstNameFemale;// "Miruna"http:// Generates a random Personal Numerical Code (CNP)echo$faker->cnp;// "2800523081231"echo$faker->cnp($gender=NULL,$century=NULL,$county=NULL);// Valid option values://? $gender: m, f, 1, 2//? $century: 1800, 1900, 2000, 1, 2, 3, 4, 5, 6//? $county: 2 letter ISO 3166-2:RO county codes and B1-B6 for Bucharest's 6 sectors

Faker\Provider\ro_RO\PhoneNumber

tollFreePhoneNumber;// "0800123456"http:// Generates a random premium-rate phone numberecho$faker->premiumRatePhoneNumber;// "0900123456"

Faker\Provider\ru_RU\Payment

bank;// "ОТП Банк"

Faker\Provider\sv_SE\Payment

bankAccountNumber;// "SE5018548608468284909192"

Faker\Provider\sv_SE\Person

personalIdentityNumber()// '950910-0799'//Since the numbers are different for male and female persons, optionally you can specify gender.echo$faker->personalIdentityNumber('female')// '950910-0781'

Third-Party Libraries Extending/Based On Faker

Symfony2 bundles:

BazingaFakerBundle: Put the awesome Faker library into the Symfony2 DIC and populate your database with fake data.

AliceBundle,AliceFixturesBundle: Bundles for usingAliceand Faker with data fixtures. Able to use Doctrine ORM as well as Doctrine MongoDB ODM.

FakerServiceProvider: Faker Service Provider for Silex

faker-cli: Command Line Tool for the Faker PHP library

Factory Muffin: enable the rapid creation of objects (PHP port of factory-girl)

CompanyNameGenerator: Generate names for English tech companies with class

PlaceholdItProvider: Generate images using placehold.it

dataleaA highly customizable random test data generator web app

newage-ipsum: A new aged ipsum provider for the faker library inspired byhttp://sebpearce.com/bullshit/

xml-faker: Create fake XML with Faker

faker-context: Behat context using Faker to generate testdata

CronExpressionGenerator: Faker provider for generating random, valid cron expressions.

pragmafabrik/Pomm2Faker: Faker client for Pomm database framework (PostgreSQL)

nelmio/alice: Fixtures/object generator with a yaml DSL that can use Faker as data generator.

CakePHP 2.x Fake Seeder PluginA CakePHP 2.x shell to seed your database with fake and/or fixed data.

images-generator: An image generator provider using GD for placeholder type pictures

License

Faker is released under the MIT Licence. See the bundled LICENSE file for details.

Status

API

Training

Shop

Blog

About

Pricing

? 2016GitHub, Inc.

Terms

Privacy

Security

Contact

Help

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,702評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,143評論 3 415
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,553評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,620評論 1 307
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,416評論 6 405
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 54,940評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,024評論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,170評論 0 287
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,709評論 1 333
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,597評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,784評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,291評論 5 357
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,029評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,407評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,663評論 1 280
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,403評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,746評論 2 370

推薦閱讀更多精彩內容

  • 繼我上一課的,越俎代庖nonono.一個孩子有了歸屬感和安全感,心中有愛,長大學什么,都會很幸福。要做到物我兩忘,...
    靜素love雪閱讀 121評論 0 0
  • 那一夜,她的翦水秋瞳里滿滿的都是他的影子,他們緊緊相依,原以為能一生一代一雙人這般地走下去,誰知情深不壽,等待他們...
    梧葉飄黃閱讀 197評論 0 3
  • 密歇根州立大學有一個叫“Spartan Showstoppers”的舞蹈俱樂部,今年舉辦了幾次小型演出。Shows...
    李楊手記閱讀 551評論 9 11