2 回答
TA贡献1827条经验 获得超8个赞
你需要调用函数并返回一些东西。
function jedan() {
$f_contents = file("/ime/ime.txt");
return $f_contents[rand(0, count($f_contents) - 1)];
}
function dva() {
$f_contents = file("/prezime/prezime.txt");
return $f_contents[rand(0, count($f_contents) - 1)];
}
function tri() {
$f_contents = file("/email/email.txt");
return $f_contents[rand(0, count($f_contents) - 1)];
}
$line1 = jedan();
$line2 = dva();
$line3 = tri();
$result = "{$line1}{$line2}{$line3}";
echo $result;
或者让它不那么“湿”:
function RandomLine($url) {
$f_contents = file($url);
return $f_contents[rand(0, count($f_contents) - 1)];
}
$line1 = RandomLine("/ime/ime.txt");
$line2 = RandomLine("/prezime/prezime.txt");
$line3 = RandomLine("/email/email.txt");
$result = "{$line1}{$line2}{$line3}";
echo $result;
TA贡献1806条经验 获得超5个赞
您可以简单地使用 file_get_contents() 从文件中读取内容。在下面的场景中,我在 wamp64 文件夹中创建了三个文本文件,并读取其字符串并通过附加组合其输出。
<?php
$file1= file_get_contents('C:\wamp64\xyz.txt');
$file2= file_get_contents('C:\wamp64\abc.txt');
$file3= file_get_contents('C:\wamp64\pqr.txt');
echo $file1.$file2.$file3;
?>
- 2 回答
- 0 关注
- 109 浏览
添加回答
举报