Questions about the php custom verification code function

Source: Internet
Author: User
For questions about the php custom verification code function, please refer to the following questions: php & nbsp; custom verification code function & lt ;? Phpfunction & nbsp; random_text ($ count, & nbsp; $ rm_similar & nbsp ;=& nbsp; false) {& nbsp; $ chars & n questions about the php custom verification code function
Ask you a question:
Php custom verification code function
Function random_text ($ count, $ rm_similar = false)
{
$ Chars = array_flip (array_merge (range (0, 9), range ('A', 'z ')));
If ($ rm_similar)
{
Unset ($ chars [0], $ chars [1], $ chars [2], $ chars [5], $ chars [8],
$ Chars ['B'], $ chars ['I], $ chars ['O'], $ chars ['Q'],
$ Chars ['s'], $ chars ['u'], $ chars ['V'], $ chars ['Z']);
}

For ($ I = 0, $ text = ''; $ I <$ count; $ I ++)
{
$ Text. = array_rand ($ chars );
}
Return $ text;
}
?>
What does this code do? $ chars [5]: unset ($ chars [0], $ chars [1], $ chars [2], $ chars [5], $ chars [8],
$ Chars ['B'], $ chars ['I], $ chars ['O'], $ chars ['Q'],
$ Chars ['s'], $ chars ['u'], $ chars ['V'], $ chars ['Z']);
How can I call this function? here is an example. Share with php:
------ Solution --------------------
 Function random_text ($ count, $ rm_similar = false)
{
$ Chars = array_flip (array_merge (range (0, 9), range ('A', 'z '))); // Generate A two-dimensional array [0-9] [A-Z] the values of the array increase sequentially, for example, ['A'] = 10, ['B'] = 11 ....
If ($ rm_similar)
{
Unset ($ chars [0], $ chars [1], $ chars [2], $ chars [5], $ chars [8],
$ Chars ['B'], $ chars ['I], $ chars ['O'], $ chars ['Q'],
$ Chars ['s'], $ chars ['u'], $ chars ['V'], $ chars ['Z']);
// Determine whether to release the values of the preceding arrays based on the $ rm_similar parameter (false by default ).
}

For ($ I = 0, $ text = ''; $ I <$ count; $ I ++)
{
$ Text. = array_rand ($ chars); // random value in the array based on $ count
}
Return $ text;
}
?>


Example:

// 1. get the 7-bit text code and remove the value in the unset
Random_text (7, true );

// 2. take the 5-bit text code without removing the value in the unset. here, the second parameter is false by default.
Random_text (5 );

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.