PHP generate random string function

怪我咯
Release: 2023-03-13 09:00:01
Original
1361 people have browsed it

<?php  

/**   
* 产生随机字符串   
*   
* 产生一个指定长度的随机字符串,并返回给用户   
*   
* @access public   
* @param int $len 产生字符串的位数   
* @return string   
*/   
function randStr($len=6) {   
$chars=&#39;ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%*&#39;; // characters to build the password from   
mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done)   
$password=&#39;&#39;;   
while(strlen($password)<$len)   
$password.=substr($chars,(mt_rand()%strlen($chars)),1);   
return $password;   
}  

?>
Copy after login

The above is the detailed content of PHP generate random string function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!