代码改变世界

PHP简单生成随机字符串自定义方法

2016-04-24 21:17  袁叶子  阅读(249)  评论(0编辑  收藏  举报
function get_randomstr($lenth = 6) {
    return get_random($lenth'123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ');
}
 
function get_random($length$chars '0123456789') {
    $hash '';
    $max strlen($chars) - 1;
    for($i = 0; $i $length$i++) {
        $hash .= $chars[mt_rand(0, $max)];
    }
    return $hash;
}