2017 © Pedro Peláez
 

library random-string-generator

Generates a random string based on a given pattern

image

ngiusti/random-string-generator

Generates a random string based on a given pattern

  • Sunday, October 29, 2017
  • by ngiusti
  • Repository
  • 1 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

RandomStringGenerator

Generates a random string based on a given string pattern, (*1)

Installation

The package can be used by adding random-string-generator to your list of dependencies in composer.json as following:, (*2)

composer require ngiusti/random-string-generator

Usage

Accepted string patterns:

Use l for lower case letter from a to z, (*3)

Use L for upper case letter from A to Z, (*4)

Use d for digit from 0 to 9, (*5)

Use p for punctuation, (*6)

Punctuation is any character on the following group:

!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, {, |,}, ~ and `, (*7)

Generate a string containing 2 lower case letters followed by 2 digits.
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('lldd'); // "ol68"
Generate a string containing 2 upper case letters.
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('LL'); // "VR"
Generate a string containing 2 punctuations.
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('pp'); // "?!"

Delimiters, (*8)

Apart from l,L,d and p, any other character is considered a delimiter. Therefore, the pattern -dl? is interpreted as : a hyphen followed by a random digit, followed by a random lower case letter, followed by a question mark., (*9)

Generate a string containing 2 letters followed by a hyphen.
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('ll-'); // "yz-"

Scape, (*10)

In order to generate a string containing the characters l,L,d and p as a delimiter you need to use the backslash twice in order to scape it., (*11)

Generate a string containing 2 digits followed by the letters lLdp.
use RandomStringGenerator\RandomStringGenerator;

$generator = new RandomStringGenerator();
$generator->generate('dd\\l\\L\\d\\p'); // "39lLdp"

The Versions

29/10 2017

dev-master

9999999-dev https://github.com/nathaliagiusti/random-string-generator

Generates a random string based on a given pattern

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

generator pattern string random

29/10 2017

v1.0.0

1.0.0.0 https://github.com/nathaliagiusti/random-string-generator

Generates a random string based on a given pattern

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

generator pattern string random