PHP生成不反复字符串
使用时间戳作为原始字符串,再随机生成五个字符随机插进去恣意位置,生成新的字符串,保证不反复。
代码以下:
function rand($len) { $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $string=time(); for(;$len>=1;$len--) { $position=rand()%strlen($chars); $position2=rand()%strlen($string); $string=substr_replace($string,substr($chars,$position,1),$position2,0); } return $string; }
引荐教程:PHP视频教程
以上就是php生成不反复字符串的细致内容,更多请关注ki4网别的相干文章!