This article will share with you a very practical code that is frequently used in projects. you can generate two non-repeated card numbers and passwords in batches. For more information, see. When it hurts, by the way, I have strengthened some of my skills in PHP's array manipulation. I wrote the following small code, which can randomly generate the array corresponding to the card number and password, and automatically repeat, without any ideas.
<? Php header ('content-Type: text/html; charset = utf-8 '); function MakeCard () {set_time_limit (0); // process the buffer ob_end_clean (); ob_implicit_flush (true); echo str_pad ("", 256); if (intval ($ _ POST ['num']> 0 )) $ num = intval ($ _ POST ['num']); // quantity if (intval ($ _ POST ['point']> 0 )) $ point = intval ($ _ POST ['point']); // point if (intval ($ _ POST ['batch']> 0 )) $ batch = intval ($ _ POST ['batch']); // if ($ _ POST ['ym']! = "") $ Ym = $ _ POST ['ym']; // else $ ym = date ('ym'); if ($ num = 0) return; $ num = $ num * 100; // number of cards, that is, the number of records echo"Start ". date ("H: I: s "). ""; for ($ I = 1; $ I <= $ num; $ I ++) {$ sn = sprintf ("% 02 s % 06 s ", $ batch, $ ym, $ I); $ seek = mt_rand (0, 9999 ). mt_rand ). mt_rand (); // 12 bits $ start = mt_rand (); $ str = strtoupper (substr (md5 ($ seek), $ start, 12 )); $ str = str_replace ("O", chr (mt_rand (65,78), $ str); $ str = str_replace ("0", chr (mt_rand (65,78 )), $ str); $ row = array ('SN '=> $ sn, 'password' => $ str, 'created' => time (), 'point' => $ point); // Check the duplicate // add the code for inserting data here. print_r ($ row);} echo "end ". date ("H: I: s "). ""; printf ("
Successfully generated: passwords for % s points
", $ Num/1e4, $ point); return $ num;} // Function End $ _ POST ['num'] = 1; $ _ POST ['point'] = 10; $ _ POST ['batch'] = 10; $ _ POST ['ym'] = '2016 '; echo MakeCard ();?>
Method 2:
<? Php $ numLen = 16; $ pwdLen = 10; $ c = 100; // Generate the 100 Group card number password $ sNumArr = range (); $ sPwdArr = array_merge ($ sNumArr, range ('A', 'z'); $ cards = array (); for ($ x = 0; $ x <$ c; $ x ++) {$ tempNumStr = array (); for ($ I = 0; $ I <$ numLen; $ I ++) {$ tempNumStr [] = array_rand ($ sNumArr );} $ tempPwdStr = array (); for ($ I = 0; $ I <$ pwdLen; $ I ++) {$ tempPwdStr [] = $ sPwdArr [array_rand ($ sPwdArr)];} $ cards [$ x] ['no'] = implode ('', $ tempNumStr ); $ cards [$ x] ['pwd'] = implode (' ', $ TempPwdStr);} array_unique ($ cards); print_r ($ cards);?>
The above is all the content of this article. I hope you will like it.