Home > php教程 > php手册 > php thinkphp generates random strings

php thinkphp generates random strings

WBOY
Release: 2016-08-26 10:12:50
Original
1529 people have browsed it

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> }

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template