PHP随机报价生成器
以下代码加载文本文件的内容,并从中随机显示一行。您可以使用它在每次加载页面时在页面上显示随机报价。
$file= "quotes.txt"; $quotes = file($file); srand((double)microtime()*1000000); $randomquote = rand(0, count($quotes)-1); echo $quotes[$randomquote];
它的工作方式是将文件加载到内存中,然后从该文件中随机选择一行。这是您可能要使用的示例文件。
This is the first quote - Person One This is the second quote - Person Two
用您自己的报价填写,然后离开。