小兔网

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

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

本教程操作环境:windows7系统、PHP5.6版,该方法适用于所有品牌电脑。

推荐:《PHP视频教程

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

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 不重复字符串的实现方法的知识。速戳>>知识兔学习精品课!