Skip to content

Commit bd5fd0d

Browse files
Add more examples in readme
1 parent 17ca04f commit bd5fd0d

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

README.md

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,24 @@ Description
99
You can install the package via composer:
1010

1111
```bash
12-
composer require stfn/php-random-string
12+
Not published yet
1313
```
1414

1515
## Usage
1616

1717
Simple example without any configuration.
1818

1919
```php
20-
use Stfn\RandomString\RandomString;
21-
2220
$string = RandomString::new()->generate();
2321

2422
echo $string; // Output: RIKdjFzuDaN12RiJ
2523
```
2624

2725
If you want to generate string consist of numbers only, you can do it like this:
2826
```php
29-
use Stfn\RandomString\StringConfig;
30-
use Stfn\RandomString\RandomString;
31-
32-
$config = StringConfig::make()->length(6)->numbersOnly();
27+
$config = StringConfig::make()
28+
->length(6)
29+
->numbersOnly();
3330

3431
$string = RandomString::fromConfig($config)->generate();
3532

@@ -38,16 +35,55 @@ echo $string; // Output: 649432
3835

3936
Or you can use your custom charset for generating random string:
4037
```php
41-
use Stfn\RandomString\StringConfig;
42-
use Stfn\RandomString\RandomString;
43-
44-
$config = StringConfig::make()->charset("ABCD1234");
38+
$config = StringConfig::make()
39+
->charset("ABCD1234");
4540

4641
$string = RandomString::fromConfig($config)->generate();
4742

4843
echo $string; // Output: 3B41B32C2A12A3A1
4944
```
5045

46+
You can use shorthand for config.
47+
```php
48+
$string = RandomString::fromArray([
49+
'length' => 6,
50+
'charset' => 'ABCD1234'
51+
])->generate();
52+
53+
echo $string; // Output: 3B41B32C2A12A3A1
54+
```
55+
56+
If you want to generate more than one string, with more than one configuration option, you can do it like this:
57+
```php
58+
use Stfn\RandomString\StringConfig;
59+
60+
$config = StringConfig::make()
61+
->charset("ABCD1234")
62+
->length(5)
63+
->prefix("PREFIX_")
64+
->suffix("_SUFFIX")
65+
->count(10)
66+
->unique()
67+
->skip(function ($string) {
68+
return in_array($string, ["PREFIX_BCD1234A_SUFFIX"]);
69+
});
70+
71+
$strings = RandomString::fromConfig($config)->generate();
72+
73+
echo $string; // Output: [
74+
"PREFIX_CAC23_SUFFIX"
75+
"PREFIX_3AAD2_SUFFIX"
76+
"PREFIX_CC21D_SUFFIX"
77+
"PREFIX_121C3_SUFFIX"
78+
"PREFIX_43ABC_SUFFIX"
79+
"PREFIX_D432A_SUFFIX"
80+
"PREFIX_43BC3_SUFFIX"
81+
"PREFIX_11BBB_SUFFIX"
82+
"PREFIX_31121_SUFFIX"
83+
"PREFIX_3AB1B_SUFFIX"
84+
];
85+
```
86+
5187
## Testing
5288

5389
```bash

0 commit comments

Comments
 (0)