Skip to content

Commit 06433b0

Browse files
author
Bram Ceulemans
committed
wip: added docs for lorem formatter
1 parent 89605ca commit 06433b0

File tree

5 files changed

+398
-267
lines changed

5 files changed

+398
-267
lines changed

docs/formatters.md

Lines changed: 1 addition & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Formatters
1+
# Available Formatters
22

33
Each of the generator properties (like `name`, `address`, and `lorem`) are called "formatters". A faker generator has
44
many of them, packaged in "providers". Here is a list of the bundled formatters in the default locale.
@@ -9,265 +9,6 @@ In all examples, a faker instance is made using the `en_US` default locale.
99
$faker = \Faker\Factory::create();
1010
```
1111

12-
### Numbers and Strings (`Faker\Provider\Base`)
13-
14-
#### # `randomDigit`
15-
16-
Generates a random integer from 0 until 9.
17-
18-
```php
19-
echo $faker->randomDigit();
20-
21-
// an integer between 0 and 10
22-
```
23-
24-
#### # `randomDigitNot`
25-
26-
Generates a random integer from 0 until 9, excluding a given number.
27-
28-
```php
29-
echo $faker->randomDigitNot(2);
30-
31-
// 1, 3, 4, 5, 6, 7, 8 or 9
32-
```
33-
34-
#### # `randomDigitNotNull`
35-
36-
Generates a random integer from 1 until 9.
37-
38-
```php
39-
echo $faker->randomDigitNotNull();
40-
41-
// an integer between 1 and 10
42-
```
43-
44-
#### # `randomNumber`
45-
46-
Generates a random integer, containing between 0 and `$nbDigits` amount of digits. When the `$strict` parameter
47-
is `true`, it will only return integers with $nbDigits amount of digits.
48-
49-
```php
50-
echo $faker->randomNumber(5, false);
51-
52-
// 123, 43, 19238, 5, or 1203
53-
54-
echo $faker->randomNumber(5, true);
55-
56-
// 12643, 42931, or 32919
57-
```
58-
59-
#### # `randomFloat`
60-
61-
Generates a random float. Optionally it's possible to specify the amount of decimals.
62-
63-
The second and third parameters optionally specify a lower and upper bound respectively.
64-
65-
```php
66-
echo $faker->randomFloat();
67-
68-
// 12.9830, 2193.1232312, 102.12
69-
70-
echo $faker->randomFloat(2);
71-
72-
// 43.23, 1203.49, 3428.93
73-
74-
echo $faker->randomFloat(1, 20, 30);
75-
76-
// 21.7, 27.2, 28.1
77-
```
78-
79-
#### # `numberBetween`
80-
81-
Generates a random integer between `$min` and `$max`. By default, an integer is generated between `0`
82-
and `2,147,483,647` (32-bit integer).
83-
84-
```php
85-
echo $faker->numberBetween();
86-
87-
// 120378987, 182, 102310983
88-
89-
echo $faker->numberBetween(0, 100);
90-
91-
// 32, 87, 91, 13, 75
92-
```
93-
94-
#### # `randomLetter`
95-
96-
Generates a random character from the alphabet.
97-
98-
```php
99-
echo $faker->randomLetter();
100-
101-
// 'h', 'i', 'q'
102-
```
103-
104-
#### # `randomElements`
105-
106-
Returns `$count` amount of random element from the given array. By default, the `$count` parameter is set to 1.
107-
108-
```php
109-
echo $faker->randomElements(['a', 'b', 'c', 'd', 'e']);
110-
111-
// ['c']
112-
113-
echo $faker->randomElements(['a', 'b', 'c', 'd', 'e'], 3);
114-
115-
// ['a', 'd', 'e']
116-
```
117-
118-
#### # `randomElement`
119-
120-
Returns `$count` amount of random element from the given array. By default, the `$count` parameter is set to 1.
121-
122-
```php
123-
echo $faker->randomElement(['a', 'b', 'c', 'd', 'e']);
124-
125-
// 'c'
126-
```
127-
128-
#### # `shuffle`
129-
130-
Returns a shuffled version of either an array or string.
131-
132-
```php
133-
echo $faker->shuffle('hello-world');
134-
135-
// 'lrhoodl-ewl'
136-
137-
echo $faker->shuffle([1, 2, 3]);
138-
139-
// [3, 1, 2]
140-
```
141-
142-
#### # `numerify`
143-
144-
Generate a string where all `#` characters are replaced by digits between 0 and 10. By default, `###` is used as input.
145-
146-
```php
147-
echo $faker->numerify();
148-
149-
// '912', '271', '109', '674'
150-
151-
echo $faker->numerify('user-####');
152-
153-
// 'user-4928', 'user-3427', 'user-1280'
154-
```
155-
156-
#### # `lexify`
157-
158-
Generate a string where all `?` characters are replaces with a random letter from the Latin alphabet. By default, `????`
159-
is used as input.
160-
161-
```php
162-
echo $faker->lexify();
163-
164-
// 'sakh', 'qwei', 'adsj'
165-
166-
echo $faker->lexify('id-????');
167-
168-
// 'id-xoqe', 'id-pqpq', 'id-zpeu'
169-
```
170-
171-
#### # `bothify`
172-
173-
Generate a string where `?` characters are replaced with a random letter, and `#` characters are replaces with a random
174-
digit between 0 and 10. By default, `## ??` is used as input.
175-
176-
```php
177-
echo $faker->bothify();
178-
179-
// '46 hd', '19 ls', '75 pw'
180-
181-
echo $faker->bothify('?????-#####');
182-
183-
// 'lsadj-10298', 'poiem-98342', 'lcnsz-42938'
184-
```
185-
186-
#### # `asciify`
187-
188-
Generate a string where `*` characters are replaced with a random character from the ASCII table. By default, `****` is
189-
used as input.
190-
191-
```php
192-
echo $faker->asciify();
193-
194-
// '%Y+!', '{<"B', 'kF^a'
195-
196-
echo $faker->asciify('user-****');
197-
198-
// 'user-ntwx', 'user-PK`A', 'user-n`,X'
199-
```
200-
201-
#### # `regexify`
202-
203-
Generate a random string based on a regex. By default, an empty string is used as input.
204-
205-
```php
206-
echo $faker->regexify();
207-
208-
// ''
209-
210-
echo $faker->regexify('[A-Z]{5}[0-4]{3}');
211-
212-
// 'DRSQX201', 'FUDPA404', 'CQVIU411'
213-
```
214-
215-
### Text and Paragraphs (`Faker\Provider\Lorem`)
216-
217-
#### # `word`
218-
219-
Generate a string containing random single word.
220-
221-
```php
222-
echo $faker->word();
223-
224-
// 'molestiae', 'occaecati', 'distinctio'
225-
```
226-
227-
#### # `words`
228-
229-
Generate an array containing a specified amount of random words.
230-
231-
Optionally, a second boolean parameter can be supplied. When true, a string will be returned instead of an array.
232-
233-
```php
234-
echo $faker->words();
235-
236-
// ['praesentium', 'possimus', 'modi']
237-
238-
echo $faker->words(5);
239-
240-
// ['molestias', 'repellendus', 'qui', 'temporibus', 'ut']
241-
242-
echo $faker->words(3, true);
243-
244-
// 'placeat vero saepe'
245-
```
246-
247-
#### # `sentence`
248-
249-
Generate a sentence containing a given amount of words. By default, `6` words is used.
250-
251-
Optionally, a second boolean parameter can be supplied. When `false`, only sentences with the given amount of words will
252-
be generated. By default, `sentence` will deviate from the given amount by +/- 40%.
253-
254-
```php
255-
echo $faker->sentence();
256-
257-
// 'Sit vitae voluptas sint non voluptates.'
258-
259-
echo $faker->sentence(3);
260-
261-
// 'Laboriosam non voluptas.'
262-
```
263-
264-
```php
265-
sentences($nb = 3, $asText = false); // ['Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.']
266-
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.'
267-
paragraphs($nb = 3, $asText = false); // ['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.']
268-
text($maxNbChars = 200) // 'Fuga totam reiciendis qui architecto fugiat nemo. Consequatur recusandae qui cupiditate eos quod.'
269-
```
270-
27112
### `Faker\Provider\en_US\Person`
27213

27314
```php

0 commit comments

Comments
 (0)