Home > Backend Development > PHP Tutorial > PHP function to generate a random string of custom length_PHP tutorial

PHP function to generate a random string of custom length_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:30:38
Original
989 people have browsed it

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764899.htmlTechArticleThis article mainly introduces the sharing of functions for generating custom length random strings in PHP. Friends who need it can refer to it. PHP randomly generates strings and you can define the length you need,...
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template