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

WBOY
Release: 2016-07-13 10:30:38
Original
954 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,...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template