标签:== pre size span 字符串 int ram param 手机
/**
* echo nRand(‘mail‘);die;
* @param array $type
* @param int $len
* @return int|string
*/
function nRand($type=[],$len= 20)
{
$t = gettype($type);
if($t === ‘string‘){
$rand="";
if($type == ‘phone‘)
{
$rand=0;
for ($i = 1; $i < 9; ++$i) {
$rand .=mt_rand(0, 9);
}
return (int) ‘13‘.$rand;
}elseif($type === ‘mail‘){
$rand=0;
for ($i = 1; $i < 9; ++$i) {
$rand .=mt_rand(0, 9);
}
return ‘13‘.$rand.‘@‘.$rand.‘com‘;
}else{
for ($i = 0; $i < $len; $i++)
{
$rand .= chr(mt_rand(33, 126));
}
return $rand;
}
}elseif ($t === "integer"){
$rand=0;
$str = ‘0123456789‘;
$max=strlen($str)-1;
for ($i = 1; $i < $len; ++$i) {
$rand .=$str[mt_rand(0, $max)];
}
return $rand;
}else{
$rand = ‘‘;
$str = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwsyz0123456789‘;
$max=strlen($str)-1;
for ($i = 1; $i <= $len; ++$i) {
$rand .=$str[mt_rand(0, $max)];
}
return $rand;
}
}
标签:== pre size span 字符串 int ram param 手机
原文地址:http://www.cnblogs.com/q1104460935/p/7045124.html