这是一个生成你正在描述的随机单词的函数.它没有使用字母"Q",因为那个字母不断发出不可发音的字样.
<?php
//generate random consonants separated by vowels
function generate_faux_word($letters = 5){
//define arrays of consonants and vowels
//no q, it's tough to remember
$consonants = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');
$vowels = array('a', 'e', 'i', 'o', 'u');
$ret_word = "";
$consonant_toggle = true;
//randomly choose a consonant then a vowel until the word is as long as the parameter
while(strlen($ret_word) < $letters){
if ($consonant_toggle){
$ret_word .= $consonants[array_rand($consonants)];
$consonant_toggle = false;
}else{
$ret_word .= $vowels[array_rand($vowels)];
$consonant_toggle = true;
}
}
return $ret_word;
}
echo generate_faux_word();
echo "<br />";
echo generate_faux_word();
echo "<br />";
echo generate_faux_word(6);
echo "<br />";
echo generate_faux_word(4);
?>
Run Code Online (Sandbox Code Playgroud)
示例输出是:muher sucok kozive xaso
有一个用于生成可发音单词的库.这是图书馆的链接:http://www.multicians.org/thvv/gpw.html.该页面上有一个指向Java源文件的链接.我首先找到了它的python库:http://www.preetk.com/node/pygpw-generate-pronouncable-words/