Created
November 23, 2018 19:23
-
-
Save HenriqueSilverio/e1b6b1fa147d1ff18fa23c106453b4a1 to your computer and use it in GitHub Desktop.
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 str_random($length = 16) | |
{ | |
$string = ''; | |
$len = strlen($string); | |
while ($len < $length) { | |
$size = $length - $len; | |
$bytes = random_bytes($size); | |
$bytes = base64_encode($bytes); | |
$blackList = ['/', '+', '=']; | |
$cleanStr = str_replace($blackList, '', $bytes); | |
$string .= substr($cleanStr, 0, $size); | |
$len = strlen($string); | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment