PHP generates a random string with specified number of digits (length)

WBOY
Release: 2016-07-25 08:55:26
Original
1624 people have browsed it
  1. /**
  2. * Generate a string of specified length
  3. * by bbs.it-home.org
  4. */
  5. function create_random_string($random_length) {
  6. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  7. $random_string = '';
  8. for ($i = 0; $ i < $random_length; $i++) {
  9. $random_string .= $chars [mt_rand(0, strlen($chars) - 1)];
  10. }
  11. return $random_string;
  12. }
Copy code

Write It's a bit simpler. The value range of the random string is random{0-9,A-Z,a-z}.

>>>> Articles you may be interested in: PHP random string generation function php function to generate random string Two examples of generating random strings with PHP Two ways to generate random strings with PHP A simple php function to randomly generate strings Very practical 3 PHP random string function generators Example of php generating random numbers php creates code that can read random strings Code to generate a random string using php Example code for php to generate random numbers and letters



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