This article mainly introduces the function sharing of PHP to generate random strings of custom length. Friends who need it can refer to it
php randomly generates strings and you can define the length you need. This is often encountered in actual application development.
The code is as follows:
// Randomly generate string
Function random($length) {
srand(date("s"));
$possible_charactors = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$string = "";
while(strlen($string)<$length) {
$string .= substr($possible_charactors,(rand()%(strlen($possible_charactors))),1);
}
return($string);
}
Note: For more exciting articles, please pay attention to the Programming Tutorial column of Bangke Home.