Home >Backend Development >PHP Tutorial >PHP generate random string function_PHP tutorial

PHP generate random string function_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:59:50824browse


/**
* Generate a random string
*
* Generate a random string of specified length and return it to the user
*
* @access public
* @param int $len Generate Number of digits in string
* @return string
*/  
function randStr($len=6) {  
$chars='ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%*'; // characters to build the password from  
mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done)  
$password='';  
while(strlen($password)<$len)  
$password.=substr($chars,(mt_rand()%strlen($chars)),1);  
return $password;  


?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/317275.htmlTechArticle?php /***Generate a random string * *Generate a random string of specified length and return it to the user * *@accesspublic *@paramint$len The number of digits in the generated string *@returnstring*/ functionra...
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