提前感谢任何人回答/试图回答我的问题。
我目前正在使用php脚本生成随机字符串,但现在我想生成一个人的随机名称,而不是只生成一个随机字符串。我的旧代码看起来像这样:
<?php
function RandomString($length) {
$keys = array_merge(range('a', 'z'), range('A', 'Z'));
for($i=0; $i < $length; $i++) {
$key .= $keys[array_rand($keys)];
}
return $key;
}
print RandomString(6);
?>
再次感谢你。
答案 0 :(得分:1)
<?php
function randomName() {
$names = array(
'Juan',
'Luis',
'Pedro',
// and so on
);
return $names[rand ( 0 , count($names) -1)];
}
print randomName();
答案 1 :(得分:1)
名字只是开始!看看Faker:
<?php
require_once '/path/to/Faker/src/autoload.php';
$faker = Faker\Factory::create();
echo $faker->name;
echo $faker->phoneNumber;
echo $faker->paragraph(2);
这可能会产生以下输出......每次都不同:
John Smith
800-867-5309
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus
et magnis dis parturient montes, nascetur ridiculus mus. Donec quam
felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla
consequat massa quis enim. Donec pede justo, fringilla vel, aliquet
nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a,
venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.
Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean
vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat
vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra
quis, feugiat a, tellus.
答案 2 :(得分:1)
我发现了这个问题,因为我需要同样的东西。对于其他任何人,这是一个将50个名字与50个姓氏配对使用的功能,从而提供2500种可能性。它基于公认的答案,随机名称由http://listofrandomnames.com
提供echo randomName();
function randomName() {
$firstname = array(
'Johnathon',
'Anthony',
'Erasmo',
'Raleigh',
'Nancie',
'Tama',
'Camellia',
'Augustine',
'Christeen',
'Luz',
'Diego',
'Lyndia',
'Thomas',
'Georgianna',
'Leigha',
'Alejandro',
'Marquis',
'Joan',
'Stephania',
'Elroy',
'Zonia',
'Buffy',
'Sharie',
'Blythe',
'Gaylene',
'Elida',
'Randy',
'Margarete',
'Margarett',
'Dion',
'Tomi',
'Arden',
'Clora',
'Laine',
'Becki',
'Margherita',
'Bong',
'Jeanice',
'Qiana',
'Lawanda',
'Rebecka',
'Maribel',
'Tami',
'Yuri',
'Michele',
'Rubi',
'Larisa',
'Lloyd',
'Tyisha',
'Samatha',
);
$lastname = array(
'Mischke',
'Serna',
'Pingree',
'Mcnaught',
'Pepper',
'Schildgen',
'Mongold',
'Wrona',
'Geddes',
'Lanz',
'Fetzer',
'Schroeder',
'Block',
'Mayoral',
'Fleishman',
'Roberie',
'Latson',
'Lupo',
'Motsinger',
'Drews',
'Coby',
'Redner',
'Culton',
'Howe',
'Stoval',
'Michaud',
'Mote',
'Menjivar',
'Wiers',
'Paris',
'Grisby',
'Noren',
'Damron',
'Kazmierczak',
'Haslett',
'Guillemette',
'Buresh',
'Center',
'Kucera',
'Catt',
'Badon',
'Grumbles',
'Antes',
'Byron',
'Volkman',
'Klemp',
'Pekar',
'Pecora',
'Schewe',
'Ramage',
);
$name = $firstname[rand ( 0 , count($firstname) -1)];
$name .= ' ';
$name .= $lastname[rand ( 0 , count($lastname) -1)];
return $name;
}