|
| 1 | +# Formatters |
| 2 | +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. |
| 3 | + |
| 4 | +### `Faker\Provider\Base` |
| 5 | + |
| 6 | +```text |
| 7 | +randomDigit // 7 |
| 8 | +randomDigitNot(5) // 0, 1, 2, 3, 4, 6, 7, 8, or 9 |
| 9 | +randomDigitNotNull // 5 |
| 10 | +randomNumber($nbDigits = NULL, $strict = false) // 79907610 |
| 11 | +randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL) // 48.8932 |
| 12 | +numberBetween($min = 1000, $max = 9000) // 8567 |
| 13 | +randomLetter // 'b' |
| 14 | +// returns randomly ordered subsequence of a provided array |
| 15 | +randomElements($array = array ('a','b','c'), $count = 1) // array('c') |
| 16 | +randomElement($array = array ('a','b','c')) // 'b' |
| 17 | +shuffle('hello, world') // 'rlo,h eoldlw' |
| 18 | +shuffle(array(1, 2, 3)) // array(2, 1, 3) |
| 19 | +numerify('Hello ###') // 'Hello 609' |
| 20 | +lexify('Hello ???') // 'Hello wgt' |
| 21 | +bothify('Hello ##??') // 'Hello 42jz' |
| 22 | +asciify('Hello ***') // 'Hello R6+' |
| 23 | +regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej |
| 24 | +``` |
| 25 | + |
| 26 | +### `Faker\Provider\Lorem` |
| 27 | + |
| 28 | +```text |
| 29 | +word // 'aut' |
| 30 | +words($nb = 3, $asText = false) // array('porro', 'sed', 'magni') |
| 31 | +sentence($nbWords = 6, $variableNbWords = true) // 'Sit vitae voluptas sint non voluptates.' |
| 32 | +sentences($nb = 3, $asText = false) // array('Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.') |
| 33 | +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.' |
| 34 | +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.') |
| 35 | +text($maxNbChars = 200) // 'Fuga totam reiciendis qui architecto fugiat nemo. Consequatur recusandae qui cupiditate eos quod.' |
| 36 | +``` |
| 37 | + |
| 38 | +### `Faker\Provider\en_US\Person` |
| 39 | + |
| 40 | + title($gender = null|'male'|'female') // 'Ms.' |
| 41 | + titleMale // 'Mr.' |
| 42 | + titleFemale // 'Ms.' |
| 43 | + suffix // 'Jr.' |
| 44 | + name($gender = null|'male'|'female') // 'Dr. Zane Stroman' |
| 45 | + firstName($gender = null|'male'|'female') // 'Maynard' |
| 46 | + firstNameMale // 'Maynard' |
| 47 | + firstNameFemale // 'Rachel' |
| 48 | + lastName // 'Zulauf' |
| 49 | + |
| 50 | +### `Faker\Provider\en_US\Address` |
| 51 | + |
| 52 | + cityPrefix // 'Lake' |
| 53 | + secondaryAddress // 'Suite 961' |
| 54 | + state // 'NewMexico' |
| 55 | + stateAbbr // 'OH' |
| 56 | + citySuffix // 'borough' |
| 57 | + streetSuffix // 'Keys' |
| 58 | + buildingNumber // '484' |
| 59 | + city // 'West Judge' |
| 60 | + streetName // 'Keegan Trail' |
| 61 | + streetAddress // '439 Karley Loaf Suite 897' |
| 62 | + postcode // '17916' |
| 63 | + address // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473' |
| 64 | + country // 'Falkland Islands (Malvinas)' |
| 65 | + latitude($min = -90, $max = 90) // 77.147489 |
| 66 | + longitude($min = -180, $max = 180) // 86.211205 |
| 67 | + |
| 68 | +### `Faker\Provider\en_US\PhoneNumber` |
| 69 | + |
| 70 | + phoneNumber // '201-886-0269 x3767' |
| 71 | + tollFreePhoneNumber // '(888) 937-7238' |
| 72 | + e164PhoneNumber // '+27113456789' |
| 73 | + |
| 74 | +### `Faker\Provider\en_US\Company` |
| 75 | + |
| 76 | + catchPhrase // 'Monitored regional contingency' |
| 77 | + bs // 'e-enable robust architectures' |
| 78 | + company // 'Bogan-Treutel' |
| 79 | + companySuffix // 'and Sons' |
| 80 | + jobTitle // 'Cashier' |
| 81 | + |
| 82 | +### `Faker\Provider\en_US\Text` |
| 83 | + |
| 84 | + 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." |
| 85 | + |
| 86 | +### `Faker\Provider\DateTime` |
| 87 | + |
| 88 | + unixTime($max = 'now') // 58781813 |
| 89 | + dateTime($max = 'now', $timezone = null) // DateTime('2008-04-25 08:37:17', 'UTC') |
| 90 | + dateTimeAD($max = 'now', $timezone = null) // DateTime('1800-04-29 20:38:49', 'Europe/Paris') |
| 91 | + iso8601($max = 'now') // '1978-12-09T10:10:29+0000' |
| 92 | + date($format = 'Y-m-d', $max = 'now') // '1979-06-09' |
| 93 | + time($format = 'H:i:s', $max = 'now') // '20:49:42' |
| 94 | + dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = null) // DateTime('2003-03-15 02:00:49', 'Africa/Lagos') |
| 95 | + dateTimeInInterval($startDate = '-30 years', $interval = '+ 5 days', $timezone = null) // DateTime('2003-03-15 02:00:49', 'Antartica/Vostok') |
| 96 | + dateTimeThisCentury($max = 'now', $timezone = null) // DateTime('1915-05-30 19:28:21', 'UTC') |
| 97 | + dateTimeThisDecade($max = 'now', $timezone = null) // DateTime('2007-05-29 22:30:48', 'Europe/Paris') |
| 98 | + dateTimeThisYear($max = 'now', $timezone = null) // DateTime('2011-02-27 20:52:14', 'Africa/Lagos') |
| 99 | + dateTimeThisMonth($max = 'now', $timezone = null) // DateTime('2011-10-23 13:46:23', 'Antarctica/Vostok') |
| 100 | + amPm($max = 'now') // 'pm' |
| 101 | + dayOfMonth($max = 'now') // '04' |
| 102 | + dayOfWeek($max = 'now') // 'Friday' |
| 103 | + month($max = 'now') // '06' |
| 104 | + monthName($max = 'now') // 'January' |
| 105 | + year($max = 'now') // '1993' |
| 106 | + century // 'VI' |
| 107 | + timezone // 'Europe/Paris' |
| 108 | + |
| 109 | +Methods accepting a `$timezone` argument default to `date_default_timezone_get()`. You can pass a custom timezone string to each method, or define a custom timezone for all time methods at once using `$faker::setDefaultTimezone($timezone)`. |
| 110 | + |
| 111 | +### `Faker\Provider\Internet` |
| 112 | + |
| 113 | + email // 'tkshlerin@collins.com' |
| 114 | + safeEmail // 'king.alford@example.org' |
| 115 | + freeEmail // 'bradley72@gmail.com' |
| 116 | + companyEmail // 'russel.durward@mcdermott.org' |
| 117 | + freeEmailDomain // 'yahoo.com' |
| 118 | + safeEmailDomain // 'example.org' |
| 119 | + userName // 'wade55' |
| 120 | + password // 'k&|X+a45*2[' |
| 121 | + domainName // 'wolffdeckow.net' |
| 122 | + domainWord // 'feeney' |
| 123 | + tld // 'biz' |
| 124 | + url // 'http://www.skilesdonnelly.biz/aut-accusantium-ut-architecto-sit-et.html' |
| 125 | + slug // 'aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum' |
| 126 | + ipv4 // '109.133.32.252' |
| 127 | + localIpv4 // '10.242.58.8' |
| 128 | + ipv6 // '8e65:933d:22ee:a232:f1c1:2741:1f10:117c' |
| 129 | + macAddress // '43:85:B7:08:10:CA' |
| 130 | + |
| 131 | +### `Faker\Provider\UserAgent` |
| 132 | + |
| 133 | + userAgent // 'Mozilla/5.0 (Windows CE) AppleWebKit/5350 (KHTML, like Gecko) Chrome/13.0.888.0 Safari/5350' |
| 134 | + chrome // 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5) AppleWebKit/5312 (KHTML, like Gecko) Chrome/14.0.894.0 Safari/5312' |
| 135 | + firefox // 'Mozilla/5.0 (X11; Linuxi686; rv:7.0) Gecko/20101231 Firefox/3.6' |
| 136 | + 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' |
| 137 | + opera // 'Opera/8.25 (Windows NT 5.1; en-US) Presto/2.9.188 Version/10.00' |
| 138 | + internetExplorer // 'Mozilla/5.0 (compatible; MSIE 7.0; Windows 98; Win 9x 4.90; Trident/3.0)' |
| 139 | + |
| 140 | +### `Faker\Provider\Payment` |
| 141 | + |
| 142 | + creditCardType // 'MasterCard' |
| 143 | + creditCardNumber // '4485480221084675' |
| 144 | + creditCardExpirationDate // 04/13 |
| 145 | + creditCardExpirationDateString // '04/13' |
| 146 | + creditCardDetails // array('MasterCard', '4485480221084675', 'Aleksander Nowak', '04/13') |
| 147 | + // Generates a random IBAN. Set $countryCode to null for a random country |
| 148 | + iban($countryCode) // 'IT31A8497112740YZ575DJ28BP4' |
| 149 | + swiftBicNumber // 'RZTIAT22263' |
| 150 | + |
| 151 | +### `Faker\Provider\Color` |
| 152 | + |
| 153 | + hexcolor // '#fa3cc2' |
| 154 | + rgbcolor // '0,255,122' |
| 155 | + rgbColorAsArray // array(0,255,122) |
| 156 | + rgbCssColor // 'rgb(0,255,122)' |
| 157 | + safeColorName // 'fuchsia' |
| 158 | + colorName // 'Gainsbor' |
| 159 | + hslColor // '340,50,20' |
| 160 | + hslColorAsArray // array(340,50,20) |
| 161 | + |
| 162 | +### `Faker\Provider\File` |
| 163 | + |
| 164 | + fileExtension // 'avi' |
| 165 | + mimeType // 'video/x-msvideo' |
| 166 | + // Copy a random file from the source to the target directory and returns the fullpath or filename |
| 167 | + file($sourceDir = '/tmp', $targetDir = '/tmp') // '/path/to/targetDir/13b73edae8443990be1aa8f1a483bc27.jpg' |
| 168 | + file($sourceDir, $targetDir, false) // '13b73edae8443990be1aa8f1a483bc27.jpg' |
| 169 | + |
| 170 | +### `Faker\Provider\Image` |
| 171 | + |
| 172 | + // Image generation provided by Placeholder (https://placeholder.com/) |
| 173 | + imageUrl($width = 640, $height = 480) // 'https://via.placeholder.com/640x480.png/000044?text=inventore' |
| 174 | + imageUrl($width, $height, 'cats') // 'https://via.placeholder.com/640x480.png/0022ff?text=cats+quia' |
| 175 | + imageUrl($width, $height, 'cats', true, 'Faker') // 'https://via.placeholder.com/640x480.png/00ddcc?text=cats+Faker+labore' |
| 176 | + imageUrl($width, $height, 'cats', true, 'Faker', true) // 'https://via.placeholder.com/640x480.png/CCCCCC?text=cats+Faker+sit' Monochrome image |
| 177 | + image($dir = '/tmp', $width = 640, $height = 480) // '/tmp/13b73edae8443990be1aa8f1a483bc27.jpg' |
| 178 | + image($dir, $width, $height, 'cats') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat! |
| 179 | + image($dir, $width, $height, 'cats', false) // '13b73edae8443990be1aa8f1a483bc27.jpg' it's a filename without path |
| 180 | + image($dir, $width, $height, 'cats', true, false) // it's a no randomize images (default: `true`) |
| 181 | + image($dir, $width, $height, 'cats', true, true, 'Faker') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat with 'Faker' text. Default, `null`. |
| 182 | + |
| 183 | + |
| 184 | +### `Faker\Provider\Uuid` |
| 185 | + |
| 186 | + uuid // '7e57d004-2b97-0e7a-b45f-5387367791cd' |
| 187 | + |
| 188 | +### `Faker\Provider\Barcode` |
| 189 | + |
| 190 | + ean13 // '4006381333931' |
| 191 | + ean8 // '73513537' |
| 192 | + isbn13 // '9790404436093' |
| 193 | + isbn10 // '4881416324' |
| 194 | + |
| 195 | +### `Faker\Provider\Miscellaneous` |
| 196 | + |
| 197 | + boolean // false |
| 198 | + boolean($chanceOfGettingTrue = 50) // true |
| 199 | + md5 // 'de99a620c50f2990e87144735cd357e7' |
| 200 | + sha1 // 'f08e7f04ca1a413807ebc47551a40a20a0b4de5c' |
| 201 | + sha256 // '0061e4c60dac5c1d82db0135a42e00c89ae3a333e7c26485321f24348c7e98a5' |
| 202 | + locale // en_UK |
| 203 | + countryCode // UK |
| 204 | + languageCode // en |
| 205 | + currencyCode // EUR |
| 206 | + emoji // 😁 |
| 207 | + |
| 208 | +### `Faker\Provider\Biased` |
| 209 | + |
| 210 | + // get a random number between 10 and 20, |
| 211 | + // with more chances to be close to 20 |
| 212 | + biasedNumberBetween($min = 10, $max = 20, $function = 'sqrt') |
| 213 | + |
| 214 | +### `Faker\Provider\HtmlLorem` |
| 215 | + |
| 216 | + // Generate HTML document which is no more than 2 levels deep, and no more than 3 elements wide at any level. |
| 217 | + randomHtml(2,3) // <html><head><title>Aut illo dolorem et accusantium eum.</title></head><body><form action="example.com" method="POST"><label for="username">sequi</label><input type="text" id="username"><label for="password">et</label><input type="password" id="password"></form><b>Id aut saepe non mollitia voluptas voluptas.</b><table><thead><tr><tr>Non consequatur.</tr><tr>Incidunt est.</tr><tr>Aut voluptatem.</tr><tr>Officia voluptas rerum quo.</tr><tr>Asperiores similique.</tr></tr></thead><tbody><tr><td>Sapiente dolorum dolorem sint laboriosam commodi qui.</td><td>Commodi nihil nesciunt eveniet quo repudiandae.</td><td>Voluptates explicabo numquam distinctio necessitatibus repellat.</td><td>Provident ut doloremque nam eum modi aspernatur.</td><td>Iusto inventore.</td></tr><tr><td>Animi nihil ratione id mollitia libero ipsa quia tempore.</td><td>Velit est officia et aut tenetur dolorem sed mollitia expedita.</td><td>Modi modi repudiandae pariatur voluptas rerum ea incidunt non molestiae eligendi eos deleniti.</td><td>Exercitationem voluptatibus dolor est iste quod molestiae.</td><td>Quia reiciendis.</td></tr><tr><td>Inventore impedit exercitationem voluptatibus rerum cupiditate.</td><td>Qui.</td><td>Aliquam.</td><td>Autem nihil aut et.</td><td>Dolor ut quia error.</td></tr><tr><td>Enim facilis iusto earum et minus rerum assumenda quis quia.</td><td>Reprehenderit ut sapiente occaecati voluptatum dolor voluptatem vitae qui velit.</td><td>Quod fugiat non.</td><td>Sunt nobis totam mollitia sed nesciunt est deleniti cumque.</td><td>Repudiandae quo.</td></tr><tr><td>Modi dicta libero quisquam doloremque qui autem.</td><td>Voluptatem aliquid saepe laudantium facere eos sunt dolor.</td><td>Est eos quis laboriosam officia expedita repellendus quia natus.</td><td>Et neque delectus quod fugit enim repudiandae qui.</td><td>Fugit soluta sit facilis facere repellat culpa magni voluptatem maiores tempora.</td></tr><tr><td>Enim dolores doloremque.</td><td>Assumenda voluptatem eum perferendis exercitationem.</td><td>Quasi in fugit deserunt ea perferendis sunt nemo consequatur dolorum soluta.</td><td>Maxime repellat qui numquam voluptatem est modi.</td><td>Alias rerum rerum hic hic eveniet.</td></tr><tr><td>Tempore voluptatem.</td><td>Eaque.</td><td>Et sit quas fugit iusto.</td><td>Nemo nihil rerum dignissimos et esse.</td><td>Repudiandae ipsum numquam.</td></tr><tr><td>Nemo sunt quia.</td><td>Sint tempore est neque ducimus harum sed.</td><td>Dicta placeat atque libero nihil.</td><td>Et qui aperiam temporibus facilis eum.</td><td>Ut dolores qui enim et maiores nesciunt.</td></tr><tr><td>Dolorum totam sint debitis saepe laborum.</td><td>Quidem corrupti ea.</td><td>Cum voluptas quod.</td><td>Possimus consequatur quasi dolorem ut et.</td><td>Et velit non hic labore repudiandae quis.</td></tr></tbody></table></body></html> |
0 commit comments