Faker: PHP random data generation library

Today: 2017-07-29
Faker: A php class library that is extremely simple to use.
The main function of this class library is: after a database is just established, it is hoped to insert some random data into it to facilitate testing. Sometimes it can also be used for unit testing, using a function with a fixed random seed, and please visit the official website: https://github.com/fzaninotto/Faker


The randomly generated slogan is very interesting.

Composer installation: You can also put it in require, feel free to do so.
"require-dev": {
        "fzaninotto/faker":"1.6.0"
}


demo:
<?php
// Need to be modified according to the location of the machine's autoload.php
require __DIR__ . "/../vendor/autoload.php";

$faker = Faker\Factory::create ( "zh_CN" );//Chinese language

//Temporary shielding warning, required.
$ini_get_display_errors = ini_get("display_errors");
 ini_set('display_errors', 0);
echo <<<html
[list=1]
		[*]The warning information needs to be temporarily shielded like the code, and then open after the function ends
		[*] Note that each item is separate and unrelated to other items. So the location seems unreasonable there.
		[*]The execution time of this page is long, because too many items are adjusted, and if there are too few items, it will be very fast
		[*] The class library has some additional functions, such as ensuring that results are not repeated, associating orm, etc., but they are not very important
		[*]Official website: https://github.com/fzaninotto/Faker
[/list]
html;

foreach ( range ( 1, 2 ) as $v ) {
	$arr = [
			// Personal information
			'姓名 name' => $faker->name,
			'姓 lastName' => $faker->lastName,
			'名 firstName' => $faker->firstName,
			'Mobile phone' => $faker->phoneNumber,
			'Credit Card Information Array creditCardDetails'=> $faker->creditCardDetails,
			
			// geolocation
			'纬度 latitude' =>$faker->latitude,
			'longitude longitude' =>$faker->longitude,
			'国家 country' => $faker->country,
			'country code countryCode' => $faker->countryCode,
			'Postcode: postcode'=> $faker->postcode,
			'地址 address' => $faker->address,
			'city' => $faker->city,
			'省 state'=> $faker->state,
			'Province abbreviation stateAbbr' =>$faker->stateAbbr,
			
			// company, bank, slogan
			'Company suffix companySuffix'=> $faker->companySuffix,
			'Company company'=> $faker->company,
			'Bank bank' => $faker->bank,
 			'Advertising catchPhrase'=>$faker->catchPhrase,
			
			// time
			'unixTime' => $faker->unixTime,
			'year' => $faker->year,
			'month' => $faker->month,
			'dayOfMonth'=> $faker->dayOfMonth,
			'date' =>$faker->date,
			'time' =>$faker->time,
			
			//the Internet
			'domainName' => $faker->domainName,
			'companyEmail' => $faker->companyEmail,
			'email' => $faker->email,
			'userName' => $faker->userName,
			'password' => $faker->password,
			'url' => $faker->url,
			'ipv4' => $faker->ipv4,
			'ipv6' => $faker->ipv6,
			'localIpv4' => $faker->localIpv4,
			'macAddress' => $ faker-> macAddress,
			'userAgent' => $faker->userAgent,
			
			// miscellaneous
			'Roman numerals century' => $faker->century,
			'颜色hexcolor' =>$faker->hexcolor,
			'mimeType'=>$faker->mimeType,
			'File suffix fileExtension'=>$faker->fileExtension,
			'img' => $faker->image,
			'imgurl' => $faker->imageUrl,
			'uuid'	 => $faker->uuid,
			'sha1' => $faker->sha1,
			'sha256' => $faker->sha256,
			'md5'=> $faker->md5,
			
			//text content
			'word word' => $faker->word,
			'单词 words' => $faker->words ( 5, true ),
			'Short title sentence' => $faker->sentence,
			'内容 content' => $faker->text ( 500 ) ,
			'内容 realText' => $faker->realText(100),
	];
	
	echo "<pre>". var_export ( $arr,1 )."</pre>";
}
ini_set('display_errors', $ini_get_display_errors);


Browser partial output:

    The warning information needs to be temporarily shielded like the code, and then opened after the function ends.
    Note that each item is separate and unrelated to the other items. So it seems unreasonable to have a similar location
    This page takes a long time to execute because it adjusts too many items, and if it is less, it will be very fast
    The class library has some additional functions, such as ensuring that results are not repeated, associating orm, etc., but they are not too important
    Official website: https://github.com/fzaninotto/Faker

array (
  'Name' => 'Bo Shulan',
  'LastName' => 'Li',
  'FirstName' => 'Wenbin',
  'Mobile phone' => '17763733071',
  'Credit Card Information Array creditCardDetails' =>
  array (
    'type' => 'MasterCard',
    'number' => '5379265658600441',
    'name' => 'Du Jing',
    'expirationDate' => '07/20',
  ),
  'latitude' => 87.766043999999993729943525977432727813720703125,
  'longitude' => 152.631833000000000311047188006341457366943359375,
  'country country' => 'Hawaii',
  'country code countryCode' => 'WF',
  'Postal code: postcode' => '597100',
  'Address' => 'Lanzhou Xixia District',
  'city' => 'Shanghai',
  'Province state' => 'Guangdong Province',
  'Province abbreviation stateAbbr' => 'Mongolia',
  'Company Suffix' => 'Network Limited',
  'Company' => 'Easy Power Information Co., Ltd.',
  'Bank bank' => 'Bank of China',
  'Advertising catchPhrase' => 'Time changes everything',
  'unixTime' => 385724385,
  'year' => '1998',
  'month' => '04',
  'dayOfMonth' => '23',
  'date' => '1980-06-03',
  'time' => '07:29:14',
  'domainName' => '.com',
  'companyEmail' => '[email protected]',
  'email' => '[email protected]',
  'userName' => 'jasperiores',
  'password' => 'PF@/=SrrUe\'dH5@$',
  'url' => 'http://www..com/keep-a-go-to-hate',
  'ipv4' => '89.254.9.179',
  'ipv6' => '4371:6dd6:6c18:a49a:33bf:892b:63f2:30ab',
  'localIpv4' => '0.0.0.0',
  'macAddress' => '83: F5: 2D: 41: 9E: 88',
  'userAgent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/5321 (KHTML, like Gecko) Chrome/39.0.861.0 Mobile Safari/5321',
  'Roman numeral century' => 'XIX',
  'Color hexcolor' => '#cea81a',
  'mimeType' => 'application/x-shockwave-flash',
  'File suffix fileExtension' => 'au',
  'img' => 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\52cc122599dc7789625212ef2d4086a3.jpg',
  'imgurl' => 'http://lorempixel.com/640/480/?47204',
  'uuid' => '591ad5c7-e029-325c-b536-e4c887afdbca',
  'sha1' => '03cf39e07dd8a832781f0d6fa84cfb0342ab4db7',
  'sha256' => 'f6e376ae06e9d140d1c44cb454cfbb60840b5d8022a3bb6e5cd6bcf5b9693abe',
  'md5' => '6d802d4d33d38ce1023b179b4028a6e1',
  'word word' => 'cum',
  '单词 words' => 'everyone blinded as if by his needs',
  "短标题 sentence" =>
  '内容 content' => 'The finder's advantage is to do something similar with flattery.' We often choose to seek pain or we can choose for it. That's where it's very flattering.
There's no way you will encounter a corrupted body that completely averts pain. And they either do it, and they have debts or things. They are bound to come out with complete pleasure. The distinction is chosen for pleasures, or pains for things.
The body will explain what is countered, because it is countered. What sort of physical things will happen often times.'
  '内容 realText' => 'King. The White Rabbit blew three blasts on the floor, and a crash of broken glass, from which she.',
)


Try it for yourself, you will know how interesting the slogan is! Thanks to those who added Chinese to the faker library!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327081351&siteId=291194637