fopen不显示内容

时间:2018-10-09 05:36:20

标签: php

不知道为什么我即时通讯会出现空白页吗? .txt中有数据,而php中没有错误?

<?php
$fp = fopen("products.txt", "r");
flock($fp, LOCK_SH);
$headings = fgetcsv($fp, 0, "\t");
while ($aLineOfCells = fgetcsv($fp, 0, "\t")) {
$records[] = $aLineOfCells;
}
flock($fp, LOCK_UN);
fclose($fp);
echo $aLineOfCells;
?>

这是.txt

Product.txt
ID  OID Title   Description Option  Price
01  01JAP   Japanese Model  This is the japanese option Japanese    $3000   
02  02ENG   English Model   This is the english option  English $3000

1 个答案:

答案 0 :(得分:0)

每次您回显最后一行。

每个$ aLineOfCells是一个数组。您需要将其取出。

<?php
$fp = fopen("products.txt", "r");
flock($fp, LOCK_SH);
$headings = fgetcsv($fp, 0, "\t");

$aline = '';
while ($aLineOfCells = fgetcsv($fp, 0, "\t")) {
  $records[] = $aLineOfCells[0];
  $aline = $aline . $aLineOfCells[0] . "\n";
}

flock($fp, LOCK_UN);
fclose($fp);
echo $aline;
?>