[英]PHP reading files in a loop
我在读取PHP循环中的文本文件时遇到问题。 这是我的代码更简单的示例,我知道我应该检查一下文件是否存在我的较长版本,但是无论我执行什么操作都不会读取我的文本文件。 PHP警告说文本文件为空,但不是。 PHP正在编写<br />
tho。
for ($i=1; $i<=5; $i++)
{
$myFile = "$i.txt";
$readfile = file_get_contents($myfile);
echo "$readfile <br />";
}
您在file_get_contents
传递的$myfile
,但在上面称为$myFile
(区分大小写)
变量区分大小写。
for ($i = 1; $i <= 5; $i++) {
$myFile = "$i.txt";
$readfile = file_get_contents($myFile);
echo "$readfile<br />";
}
如果您简化代码,则出错的机会就更少:
for ($i=1; $i<=5; $i++)
{
readfile("$i.txt");
echo "<br />";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.