用于批量生成随机用户名的php程序

php中文网
发布: 2016-07-25 09:04:19
原创
1275人浏览过
  1. /* 从字典文件中提取随机值 */

  2. $file1 = "./words.dic";
  3. $file2 = "./common_pass_mini.dic";
  4. $file3 = "./sys_month_date.dic";
  5. $rfile = "./5.dic";
  6. $n = 2000;
  7. //提取字典

  8. $basef = file($file1);
  9. $extf = file($file2);
  10. $extf2 = file($file3);
  11. $bf_sum = (count($basef)-1);
  12. $ef_sum = (count($extf)-1);
  13. $ef2_sum =(count($extf2)-1);
  14. //获取随机用户名

  15. for ($i=0; $i{
  16. $bn = crand(0, $bf_sum);
  17. $en = crand(0, $ef_sum);
  18. $en2 = crand(0, $ef2_sum);
  19. $name = $basef[$bn]."_".$extf[$en];
  20. $name = str_replace("/r/n", "", $name);
  21. $all_name[] = $name;
  22. }
  23. //写入文件

  24. $result = implode("/r/n", $all_name);
  25. $fp = fopen($rfile, "a+") or die('Open $rfile failed');
  26. if (fwrite($fp, $result)) {
  27. echo 'Write user succeed!';
  28. } else {
  29. echo 'Write user failed';
  30. }
  31. //生成随机数字函数

  32. function crand($start, $end)
  33. {
  34. return mt_rand($start, $end);
  35. }
  36. ?>

    立即学习PHP免费学习笔记(深入)”;

复制代码

2、合并以上生成的数个文件结果

  1. /* 合并所有生成结果 jbxue.com*/

  2. $result_file = "./result.dic";

  3. $fp = fopen($result_file, "a+") or die("Open $result_file failed");

    iWebShop开源商城系统
    iWebShop开源商城系统

    iWebShop是一款基于PHP语言及MYSQL数据库开发的B2B2C多用户开源免费的商城系统,系统支持自营和多商家入驻、集成微信商城、手机商城、移动端APP商城、三级分销、视频电商直播、微信小程序等于一体,它可以承载大数据量且性能优良,还可以跨平台,界面美观功能丰富是电商建站首选源码。iWebShop开源商城系统 v5.14 更新日志:新增商品编辑页面规格图片上传优化商品详情页面规格图片与主图切

    iWebShop开源商城系统 0
    查看详情 iWebShop开源商城系统
  4. //合并 1.dic ~ 5.dic

  5. for ($i=1; $i{
  6. $cur_file = file_get_contents($i.".dic");
  7. fwrite($fp, $cur_file);
  8. }
  9. //合并 10.dic ~ 11.dic

  10. for ($i=10; $i{
  11. $cur_file = file_get_contents($i.".dic");
  12. fwrite($fp, $cur_file);
  13. }
  14. fclose($fp);
  15. echo 'Write Succeed';
  16. ?>
复制代码

3、过滤重复值和不属于 6~16 之间的值,并生成最终可用数据

  1. /* 生成最终结果 */

  2. $file = "./result.dic";

  3. $target = "./target.dic";
  4. //去掉重复值

  5. $files = file($file);
  6. $files = array_unique($files);
  7. //判断值是不是大于6位小于16位

  8. $sum = count($files);
  9. for ($i=0; $i{
  10. if (strlen($files[$i])>=6 && strlen($files[$i])$rs[] = $files[$i];
  11. } else {
  12. continue;
  13. }
  14. }
  15. //写入目标文件

  16. $result = implode("", $rs);
  17. $fp = fopen($target, "a+") or die("Open $target failed");
  18. fwrite($fp, $result);
  19. echo 'Write succeed';
  20. ?>
复制代码


PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号