PHP code example of forever2077 / php-random-string
1. Go to this page and download the library: Download forever2077/php-random-string 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/ */
forever2077 / php-random-string example snippets
$string = RandomString::new()->generate(); // Output: RIKdjFzuDaN12RiJ
$string = RandomString::new(6)->generate(); // Output: dzGcot
// Generate string that contains only numbers
$config = StringConfig::make()
->numbersOnly();
$string = RandomString::fromConfig($config)->generate(); // Output: 9387406871490781
// Generate string that contains only lowercase letters
$config = StringConfig::make()
->lowerCaseOnly();
$string = RandomString::fromConfig($config)->generate(); // Output: hvphyfmgnvbbajve
// Generate string that contains only uppercase letters
$config = StringConfig::make()
->upperCaseOnly();
$string = RandomString::fromConfig($config)->generate(); // Output: ZIVSUDQHAMDNQAYV
$config = StringConfig::make()
->charset("ABCDEFG1234");
$string = RandomString::fromConfig($config)->generate(); // Output: 3B41B32C2A12A3A1
$config = StringConfig::make()
->numbersOnly()
->length(6)
->skip(function ($string) {
return in_array($string, ["025922", "104923"]);
});
$string = RandomString::fromConfig($config)->generate(); // Output: 083712
$config = StringConfig::make()
->length(6)
->prefix("PRE_")
->suffix("_AFTER");
$string = RandomString::fromConfig($config)->generate(); // Output: PRE_rkM7Jl_AFTER
$config = StringConfig::make()
->length(6)
->count(3);
$strings = RandomString::fromConfig($config)->generate();
// Output: ["ozBYeT", "BYjCtr", "Sw7O5b"];
$config = StringConfig::make()
->length(6)
->count(3)
->unique();
$strings = RandomString::fromConfig($config)->generate();
// Output: ["92ONRj", "Me6oym", "WbBPVc"];
$string = RandomString::fromArray(['length' => 6, 'charset' => 'ABCD1234'])->generate(); // Output: CCDA1D