国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP批量生成隨機用戶名

2024-05-04 21:52:55
字體:
來源:轉載
供稿:網友

PHP批量生成隨機用戶名,生成6 ~ 16位的用戶名若干個,主要是文本操作,同事前提是要有一個字符串包。

主要包含三個程序。

程序一:負責從字典中隨機提取數據,寫入一個新文件。(1.php)

  1. <?php 
  2. /* 從字典文件中提取隨機值 */ 
  3.  
  4. file1 = "./Words.dic"
  5. file2 = "./common_pass_mini.dic"
  6. file3 = "./Sys_Month_Date.Dic"
  7. rfile = "./5.dic"
  8. n = 2000; 
  9.  
  10. //提取字典 
  11. basef = file(file1); 
  12. extf = file(file2); 
  13. extf2 = file(file3); 
  14. bf_sum = (count(basef)-1); 
  15. ef_sum = (count(extf)-1); 
  16. ef2_sum =(count(extf2)-1); 
  17.  
  18. //獲取隨機用戶名 
  19. for (i=0; i<n; i++) 
  20. bn = crand(0, bf_sum); 
  21. en = crand(0, ef_sum); 
  22. en2 = crand(0, ef2_sum); 
  23. name = basef[bn]."_".extf[en]; 
  24. name = str_replace("/r/n""", name); 
  25. all_name[] = name; 
  26.  
  27. //寫入文件 
  28. result = implode("/r/n", all_name); 
  29. fp = fopen(rfile, "a+"or die('Open rfile failed'); 
  30. if (fwrite(fp, result)) { 
  31. echo 'Write user succeed!'
  32. else { 
  33. echo 'Write user failed'
  34.  
  35. //生成隨機數字函數 
  36. function crand(start, end
  37. return mt_rand(start, end); 
  38. ?> 

程序二:負責把上面生成的數個文件的結果合并。(2.php)

  1. <?php 
  2. /* 合并所有生成結果 knowsky.com*/ 
  3.  
  4. result_file = "./result.dic"
  5.  
  6. fp = fopen(result_file, "a+"or die("Open result_file failed"); 
  7.  
  8. //合并 1.dic ~ 5.dic 
  9. for (i=1; i<=5; i++) 
  10. cur_file = file_get_contents(i.".dic"); 
  11. fwrite(fp, cur_file); 
  12.  
  13. //合并 10.dic ~ 11.dic 
  14. for (i=10; i<=11; i++) 
  15. cur_file = file_get_contents(i.".dic"); 
  16. fwrite(fp, cur_file); 
  17. fclose(fp); 
  18. echo 'Write Succeed'
  19.  
  20. ?> 

程序三:負責過濾重復值和不屬于 6~16 之間的值并且生成最終結果(3.php)

  1. <?php 
  2. /* 生成最終結果 */ 
  3.  
  4. file = "./result.dic"
  5. target = "./target.dic"
  6.  
  7. //去掉重復值 
  8. files = file(file); 
  9. files = array_unique(files); 
  10.  
  11. //判斷值是不是大于6位小于16位 
  12. sum = count(files); 
  13. for (i=0; i<sum; i++) 
  14. if (strlen(files[i])>=6 && strlen(files[i])<=16) { 
  15. rs[] = files[i]; 
  16. else { 
  17. continue
  18.  
  19. //寫入目標文件 
  20. result = implode("", rs); 
  21. fp = fopen(target, "a+"or die("Open target failed"); 
  22. fwrite(fp, result); 
  23. echo 'Write succeed'
  24.  
  25. ?> 

搞定,上面生成了 2.7W個隨機用戶名。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 锦屏县| 修水县| 桂林市| 白玉县| 吐鲁番市| 濉溪县| 延安市| 东安县| 内黄县| 新郑市| 织金县| 兰考县| 平凉市| 卓资县| 邹城市| 云林县| 遵化市| 右玉县| 林口县| 高阳县| 大城县| 图们市| 新河县| 黄陵县| 磐安县| 延吉市| 普洱| 万安县| 林周县| 兴和县| 桂阳县| 德昌县| 大关县| 张家川| 富川| 金川县| 原阳县| 邯郸市| 永川市| 泗洪县| 宁安市|