在php中从字典中生成随机单词

Foo*_*ert 2 php random dictionary cpu-word

请查看此链接:字典中的随机条目

然而,这个例子是C#,我的问题是如何从 php 的字典中生成随机条目?

php 是否有内置的字典函数,或者我需要 API 或其他东西来执行此操作?

Far*_*ick 5

从 GitHub,您可以下载包含每行中所有字典单词的文本文件。完整的指南在这里 -在 PHP 教程中从英语词典中获取随机单词

下面是随机选择一行并获取该行单词的 PHP 代码:

<?php
$file = "words_alpha.txt";
$file_arr = file($file);
$num_lines = count($file_arr);
$last_arr_index = $num_lines - 1;
$rand_index = rand(0, $last_arr_index);
$rand_text = $file_arr[$rand_index];
echo $rand_text;
?>
Run Code Online (Sandbox Code Playgroud)

来源:用 PHP 从英语词典中获取随机单词