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

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

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

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

推荐:《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 不重复字符串的实现方法的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行