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 );