使用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,批量生成,随机用户名
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python查看自己安装的所有库并导出的命令
2022-03-01 03:03:08
![](https://img.aspxhome.com/file/2023/8/100938_0s.png)
web.config文件的中文解释
2024-05-13 09:16:08
Selenium环境变量配置(火狐浏览器)及验证实现
2022-07-22 02:24:38
![](https://img.aspxhome.com/file/2023/8/68988_0s.png)
python 读取二进制 显示图片案例
2021-10-15 17:27:45
![](https://img.aspxhome.com/file/2023/6/77636_0s.jpg)
源码编译安装MySQL8.0.20的详细教程
2024-01-22 11:55:52
![](https://img.aspxhome.com/file/2023/5/101355_0s.png)
Python 数据可视化实现5种炫酷的动态图
2023-07-22 10:46:14
![](https://img.aspxhome.com/file/2023/4/76904_0s.gif)
Python文件操作及内置函数flush原理解析
2021-07-16 06:43:38
![](https://img.aspxhome.com/file/2023/6/109406_0s.png)
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
![](https://img.aspxhome.com/file/2023/6/134886_0s.jpg)
分享最新Sublime Text4 Build 4107注册码(密钥)汉化及完美永久破解方法
2022-12-17 10:24:53
![](https://img.aspxhome.com/file/2023/9/117499_0s.png)
Python爬虫Scrapy框架CrawlSpider原理及使用案例
2023-12-23 07:41:55
python+pytest接口自动化之session会话保持的实现
2021-10-15 15:45:31
![](https://img.aspxhome.com/file/2023/3/85183_0s.jpg)
Node.js学习入门
2024-05-13 09:58:37
![](https://img.aspxhome.com/file/2023/2/125852_0s.png)
7个好用的TypeScript新功能
2024-04-23 09:04:00
![](https://img.aspxhome.com/file/2023/2/135942_0s.jpg)
MySql数据库之alter表的SQL语句集合
2024-01-21 05:31:24
SQLServer:探讨EXEC与sp_executesql的区别详解
2024-01-29 02:53:53
![](https://img.aspxhome.com/file/2023/8/122398_0s.png)