Last active
February 16, 2017 11:31
-
-
Save TLMcode/9f0b7f08292e4723086fbfa7c3e9b8ed to your computer and use it in GitHub Desktop.
PHP RndGen()
This file contains hidden or 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
function RndGen( $GenLen = 200 ) | |
{ | |
$ChrStr = ''; $nStr = ''; $MaxSet = 122; | |
// gen chr string | |
For ( $i = 0; $i <= $MaxSet; $i++ ) | |
$ChrStr .= ( ( $i > 32 && $i != 60 ) ? ltrim ( chr( 32 ) . chr( $i ) ) : "" ); | |
// shuffle chr string | |
While ( strlen( $nStr ) < $GenLen ) | |
{ | |
$ShfStr = SubStr( str_shuffle( $ChrStr ), 0, $GenLen ); | |
// $nStr .= $ShfStr; // just in case you want only a shuffle | |
$nStr .= ( preg_match ( '/\d/', $ShfStr ) && preg_match ( '/[!-\/]/', $ShfStr ) | |
&& preg_match ( '/[^-`]/', $ShfStr ) && preg_match ( '/[:-@]/', $ShfStr ) | |
&& preg_match ( '/[A-Z]/', $ShfStr ) && preg_match ( '/[a-z]/', $ShfStr ) | |
&& !preg_match ( '/[A-Z]{2}/', $ShfStr ) && !preg_match ( '/[a-z]{2}/', $ShfStr ) | |
&& !preg_match ( '/\d{2}/', ShfStr ) ? $ShfStr : "" ); | |
} | |
return SubStr( $nStr, 0, $GenLen ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment