Home  >  Article  >  php教程  >  php thinkphp generates random strings

php thinkphp generates random strings

WBOY
WBOYOriginal
2016-08-26 10:12:501506browse

php thinkphp generates a random string
function generate_password( $length = 8 ) { <br> // Password character set, you can add any characters you need <br> $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; <br> $password = ''; <br> for ( $i = 0; $i < $length; $i++ ) <br> { <br> // There are two ways to obtain characters here <br> //The first is to use substr to intercept any character in $chars; <br> //The second is to take any element of the character array $chars <br> // $password .= substr($chars, mt_rand(0, strlen($chars) – 1), 1); <br> $password .= $chars[mt_rand(0, strlen($chars) - 1)]; <br> } <br> Return $password; <br> }

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