How does PHP generate random strings that are readable? This article will share a random generation of readable strings of code, we hope to help.
This code creates a readable string that is closer to the word in the dictionary, and is practical and has password validation capabilities.
/************** * @length-length of random string (must be a multiple of 2) **************/function Readable_random_stri Ng ($length = 6) { $conso =array ("B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "s", "T", "V", "w", "X", " Y "," z "); $vocal =array ("A", "E", "I", "O", "U"); $password = ""; Srand (Double) microtime () *1000000); $max = $length/2; for ($i =1; $i <= $max; $i + +) { $password. = $conso [Rand (0,19)]; $password. = $vocal [Rand (0,4)]; } return $password; }
Related recommendations:
PHP Quick Start Summary
Summary of PHP concise functions
How PHP replaces multidimensional arrays with Str_replace