Home  >  Article  >  Backend Development  >  PHP function to generate custom length random string sharing_PHP tutorial

PHP function to generate custom length random string sharing_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:30:49881browse

php randomly generates strings and you can define the length you need. This is often encountered in actual application development.

Copy code 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);
                                                                                                                                                                                                                    ; >


http://www.bkjia.com/PHPjc/764619.htmlwww.bkjia.com

truehttp: //www.bkjia.com/PHPjc/764619.htmlTechArticlephp randomly generates strings and you can define the length you need. This is often encountered in actual application development. Copy the code The code is as follows: // Randomly generate string function random($...
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