现在我的系统从mySQL数据库中获取数据。现在,我想从3个不同的TXT文件中获取数据,然后随机显示数据。我在两个文本文件中都有多个行数据。我想使用PHP随机获取两个文件中的所有数据。然后想在两个数据源中进行分页。
任何人都可以帮助我。
您可以将文本文件行读为数组,然后随机选择一条线:
<?php
$txt1 =<<<TXT
“If you tell the truth, you don't have to remember anything.” ― Mark Twain
“Good friends, good books, and a sleepy conscience: this is the ideal life.” ― Mark Twain
“Whenever you find yourself on the side of the majority, it is time to reform (or pause and reflect).” ― Mark Twain
TXT;
$txt2 =<<<TXT
“Facts do not cease to exist because they are ignored.” ― Aldous Huxley
“Words can be like X-rays if you use them properly -- they’ll go through anything. You read and you’re pierced.” ― Aldous Huxley
“After silence, that which comes nearest to expressing the inexpressible is music.” ― Aldous Huxley,
TXT;
$lines = explode("n", $txt1 . $txt2);
$random = array_rand($lines);
echo $lines[$random];
您可以具有:
$txt1 = file_get_contents('/path/to/text/file');
等等。