webCOMAND

random::random_string()

Generate a random string.  If no parameters are specified, a URL-safe 32 random string containing only alpha-numeric characters will be returned.  In addition to a custom character array, the following predefined character array constants can be used:

  • \io_comand_util\random::ALPHANUM_CHARS (default) - A-Z, a-z, 0-9
  • \io_comand_util\random::URL_SAFE_CHARS - A-Z, a-z, 0-9, !$()<>.,-@*_^

Prototype

string random_string(int $length = 32, array $chars = NULL)

Parameters

  • length - The number of random characters to include in the returned string.
  • chars - An array of possible characters to include in the returned string.

Example

echo \io_comand_util\random::random_string() . "\n";
echo \io_comand_util\random::random_string(4, ['1','2','3','a','b','c']);
echo \io_comand_util\random::random_string(4, \io_comand_util\random::URL_SAFE_CHARS);

Result

wQFmI8fxfhPl39rf,sXeO0f
3a1b