这是我用于读取文本文件的代码。我正在使用Laravel框架。我是Laravel的新手。
public function textfile(Request $request){
$test = 'sample_remote_tempfile.txt';
$content = Storage::get('upload/'.$test);
$pieces = explode(",", $content);
foreach ($pieces as $key => $line) {
}
}
我希望我的结果变得像这样
[{
mac_address: b8:27:eb:a2:66:08,
timestamps : 1538219012280,
water_level: 16.388515,120
etc
}]
答案 0 :(得分:-2)
您应该尝试以下操作:
public function textfile(Request $request){
$test = 'sample_remote_tempfile.txt';
$content = Storage::get('upload/'.$test);
$pieces = file($content, FILE_IGNORE_NEW_LINES);
foreach ($pieces as $key => $line) {
}
}