I am creating a function that I would like to generate random strings from a given set of characters. I would like to allow users to specify a regex character class instead of requiring them to specify every single character.
For example:
function a($length, $allowed_chars){
for ($i = 0, $salt = ""; $i < $length; $i++){
$salt .= __GET_ONE_RANDOM_CHAR_FROM_ALLOWED_CHARS__;
}
}
If allowed chars is a string of all allowed characters, then this is simple:
$characterList{mt_rand(0,strlen($characterList)-1)};
I would like to be able to specify allowed chars like this "./0-9A-Za-z" instead of "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
I didint check but, i think you will understand main idea