Skip to content

Instantly share code, notes, and snippets.

@koike koike/Str.php
Created Dec 18, 2016

Embed
What would you like to do?
<?php
class Str
{
/**
* Generate a more truly "random" alpha-numeric string.
*
* @param int $length
* @return string
*/
public static function random($length = 16)
{
$string = '';
while (($len = static::length($string)) < $length) {
$size = $length - $len;
$bytes = random_bytes($size);
$string .= static::substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
}
return $string;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.