<?php
$str = "0123456789abcdefghijklmnobqrstuvwxyzABCDEFGHIJKLMNOBQRSTUVWXYZ";
$num = 4;//随机字符长度
function get_random_str($str,$num){
$rand_str = '';
$len = strlen($str) - 1;
for($i = 0;$i < $num;$i++){
//通过随机函数获取单个字符
$rand_str .= $str[rand(0,$len)];
}
return $rand_str;
}
echo get_random_str($str,$num);
效果:A4Bu
网友评论