我已经发现了几次创建随机用户名生成器的尝试,但它们实际上只是由一组附加在字符串中的随机字符组成。这对于使用it really just looks awkward as it doesn't seem very human-like instead of just a set of random characters来说已经足够了。
有一个php库来处理字典中的用户名生成,而不是随机字符生成函数
我发现的最接近的是这里:泥名,但问题是字典不是英文的。
提前谢谢。
发布于 2015-12-03 21:31:00
好吧,你总是可以自己滚:
function get_random_username(array $dictionary, $separator = '-', $min = 2, $max = 3) {
return implode(
$separator,
array_map(
function ($key) use ($dictionary) {
return trim($dictionary[$key]);
},
array_rand($dictionary, rand($min, $max))
)
);
}以下是三个用法示例。第一个使用静态数组作为word源,第二个使用fzaninotto Faker库,最后一个使用GNU字典作为word源:
var_dump(
get_random_username(
array ('foo', 'bar', 'baz', 'quux')
),
get_random_username(
\Faker\Factory::create()->unique()->words(1000)
),
get_random_username(
file('/usr/share/dict/words')
)
);示例运行:
$ php gen.php
string(12) "bar-foo-quux"
string(11) "porro-magni"
string(11) "razor-edged"发布于 2015-12-03 21:26:58
你可以自己造。首先:用id在mysql数据库中记录一些名称。然后:在PHP中,随机获取它们。
例如:
mysql表
id -- names
2.....John
3.....Melissa
.............
999.....Saba PHP代码:
<?php
$random_id= rand(1,999); //get a random id
$sql="select*from NAMES where id='$random_id'" //then get a random name with id
//Your other codes...
?>发布于 2015-12-03 21:31:00
生成随机用户名
$a = array(
'key' => 'word1',
'key2' => 'word2',
);
$random_word = $a[array_rand($array)]; 您还可以从字典中删除单词,以便生成真正唯一的随机usernames.In加法,您可以添加一些随机字符以使其更人性化,您可以将任何有效的单词字典导入到PHP数组中使用it.Finally,您可以选择两个随机单词,添加一些随机字符并生成复杂的随机用户名。
https://stackoverflow.com/questions/34076348
复制相似问题