PHP-解析txt文件
我想解析这个文件:
Case Given Predicted
No Class Class
1 ? 0 [0.80]
2 ? 0 [0.80]
3 ? 0 [0.80]
4 ? 1 [0.75]
5 ? 0 [0.80]
6 ? 0 [0.80]
7 ? 1 [0.75]
8 ? 0 [0.80]
9 ? 0 [0.80]
10 ? 0 [0.80]
11 ? 1 [0.75]
12 ? 0 [0.80]
13 ? 0 [0.80]
14 ? 0 [0.80]
15 ? 0 [0.80]
16 ? 0 [0.80]
17 ? 0 [0.80]
18 ? 0 [0.80]
19 ? 0 [0.80]
20 ? 0 [0.80]
特别是,我想从第三列(“预测类”)中获取值。我打开文件感谢:
$txt_file = file_get_contents('simone.result');
$array = explode("\n", $txt_file);
array_shift($array);
array_shift($array);
array_shift($array);
我有这个:
Array ( [0] => 1 ? 0 [0.80] [1] => 2 ? 0 [0.80]
好的,这是正确的。但我只想要这个数组的每个键中的第三个值(“0”或“1”)。有人可以帮助我吗?
太感谢了!
i'd like to parse this file:
Case Given Predicted
No Class Class
1 ? 0 [0.80]
2 ? 0 [0.80]
3 ? 0 [0.80]
4 ? 1 [0.75]
5 ? 0 [0.80]
6 ? 0 [0.80]
7 ? 1 [0.75]
8 ? 0 [0.80]
9 ? 0 [0.80]
10 ? 0 [0.80]
11 ? 1 [0.75]
12 ? 0 [0.80]
13 ? 0 [0.80]
14 ? 0 [0.80]
15 ? 0 [0.80]
16 ? 0 [0.80]
17 ? 0 [0.80]
18 ? 0 [0.80]
19 ? 0 [0.80]
20 ? 0 [0.80]
Especially, i want to take values from third column ("Predicted class").I open file thanks to:
$txt_file = file_get_contents('simone.result');
$array = explode("\n", $txt_file);
array_shift($array);
array_shift($array);
array_shift($array);
And I have this:
Array ( [0] => 1 ? 0 [0.80] [1] => 2 ? 0 [0.80]
Ok this is correct. But I want only the third value ("0" or "1") in each key of this array. Does anyone can help me please?
Thank you so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么不简单地将字符串分解为一个空格并使用您想要的值呢?
Why not just simply explode your string by a space and use the value you want?
像这样的东西吗?
Something like this?
检索文件的所有行
,然后循环它们:
如果文件写得好,这也可以工作:)
retrieve all the lines of the file
then loop on them:
as well this work if the file is well written :)