`

PHP 简单生成随机字符串

阅读更多
<?php
//生成随机字符串
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;
}
echo get_randomstr(6).'<br>';
echo get_randomstr(7);
?>

 

效果图:

 

 

 

 

 

  • 大小: 14.5 KB
1
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics