Skip to content

Commit f6bcb3f

Browse files
Add more examples
1 parent 5826579 commit f6bcb3f

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,46 @@ Not published yet
1414

1515
## Usage
1616

17+
### Basic
1718
Simple example without any configuration.
1819

1920
```php
20-
$string = RandomString::new()->generate();
21-
22-
echo $string; // Output: RIKdjFzuDaN12RiJ
21+
$string = RandomString::new()->generate(); // Output: RIKdjFzuDaN12RiJ
2322
```
2423

24+
### Predefined charset
25+
2526
If you want to generate string consist of numbers only, you can do it like this:
2627
```php
28+
// Generate string that contains only numbers
2729
$config = StringConfig::make()
28-
->length(6)
2930
->numbersOnly();
3031

31-
$string = RandomString::fromConfig($config)->generate();
32+
$string = RandomString::fromConfig($config)->generate(); // Output: 649432
33+
34+
// Generate string that contains only lower case letters
35+
$config = StringConfig::make()
36+
->lowerCaseOnly();
37+
38+
$string = RandomString::fromConfig($config)->generate(); // Output: 649432
3239

33-
echo $string; // Output: 649432
40+
// Generate string that contains only upper case letters
41+
$config = StringConfig::make()
42+
->upperCaseOnly();
43+
44+
$string = RandomString::fromConfig($config)->generate();
3445
```
3546

47+
### Custom charset
3648
Or you can use your custom charset for generating random string:
3749
```php
3850
$config = StringConfig::make()
3951
->charset("ABCD1234");
4052

41-
$string = RandomString::fromConfig($config)->generate();
42-
43-
echo $string; // Output: 3B41B32C2A12A3A1
53+
$string = RandomString::fromConfig($config)->generate(); // Output: 3B41B32C2A12A3A1
4454
```
4555

56+
### Shorthands
4657
You can use shorthand for config.
4758
```php
4859
$string = RandomString::fromArray([

0 commit comments

Comments
 (0)