$len represents the length, the code is as follows:
Copy the code The code is as follows:
/**
* Generate a random string
*
* Generate a random string of specified length and return it to the user
*
* @access public
* @param int $len Number of digits in the generated string
* @return string
*/
function randstr($len=6) {
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz0 123456789-@ #~';
// characters to build the password from
mt_srand((double)microtime()*1000000*getmypid());
// seed the random number generator (must be done)
$password='';
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}
The above introduces the code for converting integers to strings and PHP to generate random numbers or strings, including the content of converting integers to strings. I hope it will be helpful to friends who are interested in PHP tutorials.