$fp = fopen ("branches.txt", "r");
while ($branch = fgets ($fp)) {
$branch=trim($branch);
if (filesize('branches.txt') == 0){
echo "The file is DEFINITELY empty";
}
printf("%2d: ");
if ($branch === FALSE) print ("FALSE\n");
else print ($branch . "</br>");
}
while ($info = fscanf($fp, "%i %lf %lf")) {
list ($properties, $income, $expenditure) = $info;
echo $info;
}
fclose ($fp);
Text Editer:Location / String Integer Float Float
即isver heat 12 160.0 77.0
上面我有一个代码片段,我试图从tet文件中读取变量。我是PHP的新手,我无法看到我出错的地方,因为它输出的是ArrayArray,而我需要将文本文件中的数据作为变量输出。任何人都能帮我解决我的错误吗?
答案 0 :(得分:0)
您可以通过...从文件中获取变量值
file_get_contents(FILEPATH_NAME)它将以字符串格式返回文件内容,您可以通过变量进行设置
例如......
$数据的file_get_contents =($ file_path_name);
示例:HitCounter for Visitor:
$filepath_name='data/hitcounter.txt';
$val=file_get_contents($filepath_name); // asign file content in variable
$val++;
echo 'Current Visitors:'+ $val;
/*
other code for hit counter..
file_put_contents($filepath_name,$val);
*/