PHP 生成随机字符串

/**
 * 生成随机字符串
 * @author 宁佳兵 <meilijing.ning@foxmail.com>
 * @param int $length
 * @return string
 */
function createNonceStr($length = 16) {
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $str = "";
    for ($i = 0; $i < $length; $i++) {
      $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
    }
    return $str;
}

 

posted @ 2019-02-21 15:46  宁佳兵  阅读(1737)  评论(0编辑  收藏  举报