0

我想在读取文本文件时发送 JSON 对象的多次迭代。我想读取文件并将每次迭代存储在一个对象中。我在客户端的目标是遍历对象。我的以下方法是否理想?

<?php

$myFile = $_GET['filename'];

$file = fopen($myFile, "r");
$$response = "[ ";

$data = array();
$json = array();
while (!feof($file))
{
   $row = array();
   $currentLine = fgets($file);
   $parts = explode(" ", $currentLine);
   $length = sizeof($parts);
      $time = $parts[0];
      $where = $parts[$length-1];
   $json['where'] = $where;
   $json['time'] = $time;   
   $data[] = $json;
}

echo json_encode($data);
?>
4

0 回答 0