How to obtain random numbers of four letters and numbers in php _ PHP Tutorial

Source: Internet
Author: User
Php is used to obtain random numbers of four letters and numbers. Php: how to obtain random numbers with four letters and numbers. This article describes how to develop php programs, we often do some implementation on the login interface or comment interface to obtain random numbers of four letters and numbers in four php.

This article mainly introduces some four-digit verification codes on the login interface or comment interface during php program development. For more information, see

So we know that in php, a simple four-digit pure digit verification can be done with rand (,), but if we want to get a random four-digit number of letters and numbers, so how do we write functions? The following Hu Peng blog provides a complete example in the php document section.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

Function GetfourStr ($ len)

{

$ Chars_array = array (

"0", "1", "2", "3", "4", "5", "6", "7", "8", "9 ",

"A", "B", "c", "d", "e", "f", "g", "h", "I", "j ", "k ",

"L", "m", "n", "o", "p", "q", "r", "s", "t", "u ", "v ",

"W", "x", "y", "z", "A", "B", "C", "D", "E", "F ", "G ",

"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q ", "R ",

"S", "T", "U", "V", "W", "X", "Y", "Z ",

);

$ CharsLen = count ($ chars_array)-1;

$ Outputstr = "";

For ($ I = 0; $ I <$ len; $ I ++)

{

$ Outputstr. = $ chars_array [mt_rand (0, $ charsLen)];

}

Return $ outputstr;

}

Echo GetfourStr (4 );

?>

Some function parsing: mt_rand function description: mt_rand () returns a random integer.
If the optional parameters min and max are not provided, mt_rand () returns a pseudo-random number between 0 and RAND_MAX. For example, if you want a random number between 0 and 46 (including 0 and 46), use mt_rand (0, 46 ).

Ghost This article mainly introduces php program development process, we often do some things on the login interface or comment interface...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.