使用PHP批量生成随机用户名

时间:2023-07-22 13:10:10 

程序一:负责从字典中随机提取数据,写入一个新文件。(1.php)


<?php
/* 从字典文件中提取随机值 */

$file1 = "./Words.dic";
$file2 = "./common_pass_mini.dic";
$file3 = "./Sys_Month_Date.Dic";
$rfile = "./5.dic";
$n = 2000;

//提取字典
$basef = file($file1);
$extf = file($file2);
$extf2 = file($file3);
$bf_sum = (count($basef)-1);
$ef_sum = (count($extf)-1);
$ef2_sum =(count($extf2)-1);

//获取随机用户名
for ($i=0; $i<$n; $i++)
{
$bn = crand(0, $bf_sum);
$en = crand(0, $ef_sum);
$en2 = crand(0, $ef2_sum);
$name = $basef[$bn]."_".$extf[$en];
$name = str_replace("/r/n", "", $name);
$all_name[] = $name;
}

//写入文件
$result = implode("/r/n", $all_name);
$fp = fopen($rfile, "a+") or die('Open $rfile failed');
if (fwrite($fp, $result)) {
echo 'Write user succeed!';
} else {
echo 'Write user failed';
}

//生成随机数字函数
function crand($start, $end)
{
return mt_rand($start, $end);
}
?>


程序二:负责把上面生成的数个文件的结果合并。(2.php)


<?php
/* 合并所有生成结果 jb51.net*/

$result_file = "./result.dic";

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

//合并 1.dic ~ 5.dic
for ($i=1; $i<=5; $i++)
{
$cur_file = file_get_contents($i.".dic");
fwrite($fp, $cur_file);
}

//合并 10.dic ~ 11.dic
for ($i=10; $i<=11; $i++)
{
$cur_file = file_get_contents($i.".dic");
fwrite($fp, $cur_file);
}
fclose($fp);
echo 'Write Succeed';

?>


程序三:负责过滤重复值和不属于 6~16 之间的值并且生成最终结果(3.php)


<?php
/* 生成最终结果 */

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

//去掉重复值
$files = file($file);
$files = array_unique($files);

//判断值是不是大于6位小于16位
$sum = count($files);
for ($i=0; $i<$sum; $i++)
{
if (strlen($files[$i])>=6 && strlen($files[$i])<=16) {
  $rs[] = $files[$i];
} else {
  continue;
}
}

//写入目标文件
$result = implode("", $rs);
$fp = fopen($target, "a+") or die("Open $target failed");
fwrite($fp, $result);
echo 'Write succeed';
?>


基本搞定手工,上面生成了 2.7W个随机用户名,呵呵,保证够你使用。

标签:PHP,批量生成,随机用户名
0
投稿

猜你喜欢

  • python查看自己安装的所有库并导出的命令

    2022-03-01 03:03:08
  • web.config文件的中文解释

    2024-05-13 09:16:08
  • Selenium环境变量配置(火狐浏览器)及验证实现

    2022-07-22 02:24:38
  • python 读取二进制 显示图片案例

    2021-10-15 17:27:45
  • 源码编译安装MySQL8.0.20的详细教程

    2024-01-22 11:55:52
  • Python 数据可视化实现5种炫酷的动态图

    2023-07-22 10:46:14
  • Python文件操作及内置函数flush原理解析

    2021-07-16 06:43:38
  • Django 实现admin后台显示图片缩略图的例子

    2022-05-30 19:46:02
  • vbscript与javascript如何传递变量(包括服务器端与客户端)

    2008-04-09 13:46:00
  • 设计稿标注首屏线的确定始末

    2011-03-30 12:36:00
  • mysql导入导出数据中文乱码解决方法小结

    2024-01-19 17:47:45
  • python的类方法和静态方法

    2021-04-14 21:05:22
  • pytorch SENet实现案例

    2021-03-27 05:14:23
  • 分享最新Sublime Text4 Build 4107注册码(密钥)汉化及完美永久破解方法

    2022-12-17 10:24:53
  • Python爬虫Scrapy框架CrawlSpider原理及使用案例

    2023-12-23 07:41:55
  • python+pytest接口自动化之session会话保持的实现

    2021-10-15 15:45:31
  • Node.js学习入门

    2024-05-13 09:58:37
  • 7个好用的TypeScript新功能

    2024-04-23 09:04:00
  • MySql数据库之alter表的SQL语句集合

    2024-01-21 05:31:24
  • SQLServer:探讨EXEC与sp_executesql的区别详解

    2024-01-29 02:53:53
  • asp之家 网络编程 m.aspxhome.com