Skip to content

Instantly share code, notes, and snippets.

@vrkansagara
Created December 18, 2018 11:03
Show Gist options
  • Save vrkansagara/79882db409652658c7cad34ceb3104bd to your computer and use it in GitHub Desktop.
Save vrkansagara/79882db409652658c7cad34ceb3104bd to your computer and use it in GitHub Desktop.
<?php
if (!function_exists('randcomString')) {
/**
* @param number
* @return string
*/
function randcomString($length = 16)
{
$capital = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 1);
$small = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, 1);
$number = substr(str_shuffle('0123456789'), 0, 1);
$special = substr(str_shuffle("!#$%&*+-<=>@_|"), 0, 1);
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&*+-<=>@_|';
return substr(str_shuffle(str_repeat($pool, 5)), 0, $length - 4) . $capital . $small . $number . $special;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment