在php中从字典中生成随机单词
Please take a look at this link: Random entry from dictionary
That example is C#
, however, my question is how to generate a random entry from the dictionary in php?
Does php have an inbuilt function for dictionaries, or will I need an API or something else to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 GitHub,您可以下载包含每行中所有字典单词的文本文件。完整的指南在这里 - 获取PHP 教程中从英语词典中随机单词
下面是随机选择一行并获取该行单词的 PHP 代码:
来源:从 PHP 英语词典中获取随机单词
From GitHub, you can download the text file that contains all the dictionary word in each line. The complete guide is here - Get random word from English dictionary in PHP tutorial
Below is the PHP code to choose a line randomly and get the word of that line:
Source: Get random word from English dictionary in PHP
如果我正确理解了这个问题,
array_rand
可能会做你想做的事情。array_rand
might do what you want, if I understand the question correctly.为了完成汤姆的回答,我在我的一个项目中也有类似的需求,这里我的类有一个棘手的功能,即字典直接嵌入到 PHP 文件中。
Just to complete Tom answer, I had similar needs in one of my project, here my class the tricky feature the dictionary is directly embedded in the PHP file.