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