PHP _ production verification code, php production verification code
PHP creates a verification code, mainly using array-related functions
1 <? Php 2 header ("content-type: text/html; charset = UTF-8"); 3 // create an array of 3 ranges 4 $ shuzi = range ); 5 $ zimuda = range ('A', 'z'); 6 $ zimuxiao = range ('A', 'z '); 7 8 // combine the three numbers and form a new array 9 $ arr = array_merge ($ shuzi, $ zimuxiao, $ zimuda ); 10 11 // traverse the new array 12 foreach ($ arr as $ key => $ value) {13 // if the elements in the new array contain the following words, then delete it (unset ); 14 if ($ value = '0' | $ value = '1' | $ value = '2' | $ value = 'O' | $ value = 'O' 15 | $ value = 'I' | $ value = 'Z' | $ value = 'Z' | $ value = 'l ') {16 // Delete the key and the value will also delete 17 unset ($ arr [$ key]); 18} 19} 20 21 // disrupt the array element, the KEY-value-following element is disrupted by 22 shuffle ($ arr); 23 // randomly retrieve the four key values of the original array 24 $ arr_rand = array_rand ($ arr, 4 ); 25 // print the key of the original array and obtain four random verification codes 26 foreach ($ arr_rand as $ value) {27 echo $ arr [$ value]; 28} 29 30 // optimization: The numbers 0, 1, and 2 originally need to be excluded, just in the beginning of the array, continuous, when defining the range array can not be written, reduce the if judgment directly from 3. The uppercase/lowercase letter Z can also be left empty at the end.