Last active
May 6, 2019 10:32
-
-
Save ToshY/7ad8aff897a9c86aafc1417e39701b27 to your computer and use it in GitHub Desktop.
Create a random alphanumeric string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function gRS($length, $opt = '111') { | |
$r = ''; | |
//numbers only | |
$r .= ( ( (int) $opt[0] === 1) ? '012345678923456789' : ''); | |
//numbers with small letters | |
$r .= ( ( (int) $opt[1] === 1) ? 'abcdefghijklmnopqrstuvwxyz' : ''); | |
//numbers with small and capital letters | |
$r .= ( ( (int) $opt[2] === 1) ? 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : ''); | |
return ( ($r) ? substr( str_shuffle( str_repeat( $r, ceil( $length / strlen( $r ) ) ) ), 1, $length) : NULL); | |
} | |
# gRS(20); | |
Iio6KF7hNYbdmGUx2TB4 | |
# gRS(20,'101'); | |
5K4DJXW5L192REO0UFI6 | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment