php生成随机字符串函数

  1. 代码:
    /*
    @desc:生成随机字符串
    @param $len 要生成的字符串长度
    @return str 生成的字符串
    */
    function randstr($len){
    $pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ,./<>?;#:@~[]{}-_=+)(*&^%FCKpd0pound;”!';
    $strlen = mb_strlen($pattern) - 1;
    $str = "";
    for($i = 0;$i < $len;$i++){
        $str .= $pattern[mt_rand(0,$strlen)];
    }
    return $str;
    }
  2. 测试:
    $ret = randstr(10);
    var_dump($ret);
  3. 输出:
    string(10) "t8{OQ;,Sz["

当前标题:php生成随机字符串函数
标题URL:http://pwwzsj.com/article/josgii.html