PHP code example of poppy / faker
1. Go to this page and download the library: Download poppy/faker library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
poppy / faker example snippets
// use the factory to create a \Poppy\Faker\Generator instance
$faker = \Poppy\Faker\Factory::create('zh_CN');
// generate data by accessing properties
echo $faker->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.
// 随机生成时间戳
$faker->unixTime($max = 'now'); // 84146285
// 随机生成时间
$faker->dateTime($max = 'now', $timezone = date_default_timezone_get()); // DateTime Object
(
[date] => 1981-09-02 21:14:42.000000
[timezone_type] => 3
[timezone] => Asia/Shanghai
)
// dateTimeAd
$faker->dateTimeAD; // DateTime Object
(
[date] => 0308-03-16 05:39:50.000000
[timezone_type] => 3
[timezone] => Asia/Shanghai
)
// 随机生成ios8601时间
$faker->iso8601($max = 'now'); // 1991-03-04T20:59:46+0800
// 根据格式随机生成日期
$faker->date($format = 'Y-m-d', $max = 'now'); // 1983-03-01
// 根据格式随机生成时间
$faker->time($format = 'H:i:s', $max = 'now'); // 22:34:27
// 生成指定范围的时间
$faker->dateTimeBetween($startDate = '-30 years', $endDate = 'now'); // DateTime Object
(
[date] => 2006-07-12 13:47:24.000000
[timezone_type] => 3
[timezone] => Asia/Shanghai
)
// 随机生成一个指定间隔的时间
$faker->dateTimeInInterval($startDate = '-30 years', $interval = '+ 5 days', $timezone = date_default_timezone_get()); // DateTime Object
(
[date] => 1990-11-08 17:13:04.000000
[timezone_type] => 3
[timezone] => Asia/Shanghai
)
// 随机生成当前世纪的时间
$faker->dateTimeThisCentury($max = 'now', $timezone = date_default_timezone_get()); // DateTime Object
(
[date] => 1991-02-19 01:39:03.000000
[timezone_type] => 3
[timezone] => Asia/Shanghai
)
// 随机生成当前十年的时间
$faker->dateTimeThisDecade($max = 'now', $timezone = date_default_timezone_get()); // DateTime Object
(
[date] => 2013-12-25 22:46:17.000000
[timezone_type] => 3
[timezone] => Asia/Shanghai
)
// 随机生成当前年的时间
$faker->dateTimeThisYear($max = 'now', $timezone = date_default_timezone_get()); // DateTime Object
(
[date] => 2020-05-18 23:34:51.000000
[timezone_type] => 3
[timezone] => Asia/Shanghai
)
// 随机生成当前月的时间
$faker->dateTimeThisMonth($max = 'now', $timezone = date_default_timezone_get()); // DateTime Object
(
[date] => 2020-10-27 04:22:07.000000
[timezone_type] => 3
[timezone] => Asia/Shanghai
)
// 随机生成 am/pm
$faker->amPm($max = 'now'); // 下午
// 随机生成月份的某一天
$faker->dayOfMonth($max = 'now'); // 30
// 随机生成星期
$faker->dayOfWeek($max = 'now'); // 星期日
// 随机生成月份
$faker->month($max = 'now'); // 03
// 随机生成月份的名称
$faker->monthName($max = 'now'); // 十一月
// 随机生成年份
$faker->year($max = 'now'); // 2004
// 随机生成世纪
$faker->century; // XV
// 随机生成时区
$faker->timezone; // Asia/Hebron
// 随机生成bool值 false
$faker->boolean; // 1
// 平衡的生成bool值
$faker->boolean($chanceOfGettingTrue = 50); //
// Md5
$faker->md5; // 02ab746139e35599e12a2a0fc21ece2c
// Sha1
$faker->sha1; // 81308895610bbe530dec6269e4cce55044dda0dd
// Sha256
$faker->sha256; // 3cc0882a1c3d7f68298a93c32ce2f094118ad72dbe00ef35e96f4613aaecef2f
// Locale
$faker->locale; // ja_JP
// 随机生成国家编码
$faker->countryCode; // IS
// 随机生成语言编码
$faker->languageCode; // mn
// 随机生成货币代码
$faker->currencyCode; // KZT
// Emoji
$faker->emoji; // 😞
// 随机生成一个不超过 $maxDepth层的html, 任何级别上都不超过$maxWidth个元素
$faker->randomHtml($maxDepth = 2, $maxWidth = 3); // <html><head><title>言节显登.</title></head><body><form action="example.com" method="POST"><label for="username">则</label><input type="text" id="username"><label for="password">非</label><input type="password" id="password"></form><i>水线名诉呀孤起.</i></body></html>