Home  >  Article  >  php教程  >  PHP random characters

PHP random characters

WBOY
WBOYOriginal
2016-10-17 09:12:041112browse

随机字符生成
function randStr($length=4,$type="1"){
        $array = array(
            '1' => '0123456789',
            '2' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
            '3' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
        );
        $string = $array[$type];
        $count = strlen($string)-1;
        $rand = '';
        for ($i = 0; $i < $length; $i++) {
            $rand .= $string[mt_rand(0, $count)];
        }
        return $rand;
    }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn