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);
?>

效果图:

 

猜你喜欢

转载自onestopweb.iteye.com/blog/2335847