当前位置:Gxlcms > PHP教程 > php 不重复字符串的实现方法

php 不重复字符串的实现方法

时间:2021-07-01 10:21:17 帮助过:44人阅读

php不重复字符串的实现方法:首先创建一个PHP示例文件;然后通过“function rand($len){...}”方法生成不重复随机字符串即可。

推荐:《PHP视频教程》

php生成不重复随机字符串

使用时间戳作为原始字符串,再随机生成五个字符随机插入任意位置,生成新的字符串,保证不重复

  1. function rand($len)
  2. {
  3. $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  4. $string=time();
  5. for(;$len>=1;$len--)
  6. {
  7. $position=rand()%strlen($chars);
  8. $position2=rand()%strlen($string);
  9. $string=substr_replace($string,substr($chars,$position,1),$position2,0);
  10. }
  11. return $string;
  12. }
  • 该方法适用于所有型号的电脑。

以上就是php 不重复字符串的实现方法的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行