使用PHP打开文本文件 - 修复格式

时间:2015-05-14 01:10:34

标签: php format wamp fread

基本上,我的文本文件包含以下信息:

WITH PARALLEL AND SERIAL


----- [System Info] -----------------------------------------------------------

Property                  Value
Machine Type              AT/AT COMPATIBLE
Infrared (IR) Supported   No
DMI System UUID           809EC223-DAD7DD11-A2F33085-A993FFAC
UUID                      23C29E80-D7DA-11DD-A2F3-3085A993FFAC
Disk Space                Disk C: 89 GB Available, 97 GB Total, 89 GB Free
Disk Space                Disk D: 355 GB Available, 368 GB Total, 355 GB Free
Disk Space                Disk F: 274 MB Available, 3837 MB Total, 274 MB Free
Physical Memory           1724 MB Total, 1173 MB Free
Memory Load               31%
Virtual Memory            3619 MB Total, 3184 MB Free
PageFile Name             \??\C:\pagefile.sys
PageFile Size             2046 MB
In use                    35 MB
Max used                  35 MB
Registry Size             3 MB (current), 120 MB (maximum)
Profile GUID              {bef54e40-80cb-11e2-a600-806d6172696f}
The system clock interval 15 ms



----- [Motherboard] ---------------------------------------

Property         Value
Manufacturer     ASUSTeK COMPUTER INC.
Model            P8H61-M LX R2.0
Version          Rev X.0x
Serial Number    120801441113185
North Bridge     Intel ID0100 Revision 09
South Bridge     Intel ID1C5C Revision 09
CPU              Intel(R) Pentium(R) CPU G645 @ 2.90GHz
Cpu Socket       
System Slots     4 PCI
Memory Summary   
Maximum Capacity 16384 MBytes
Memory Slots     2
Error Correction None
Warning!         Accuracy of DMI data cannot be guaranteed

但是在PHP中使用此代码打开它:

<?php

if(isset($_POST["submit"])){
$myfile = fopen("baliwag_04162015.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("baliwag_04162015.txt"));
fclose($myfile);
}
?>

我得到这样的东西:

WITH PARALLEL AND SERIAL ----- [系统信息] ---------------------------------- -------------------------属性值机器类型AT / AT兼容红外线(IR)支持无DMI系统UUID 809EC223-DAD7DD11-A2F33085-A993FFAC UUID 23C29E80-D7DA-11DD-A2F3-3085A993FFAC磁盘空间磁盘C:89 GB可用,总共97 GB,89 GB可用磁盘空间磁盘D:355 GB可用,总共368 GB,355 GB可用磁盘空间磁盘F:274 MB可用, 3837 MB总计,274 MB可用物理内存1724 MB总计,1173 MB可用内存负载31%虚拟内存3619 MB总计,3184 MB可用PageFile名称\ ?? \ C:\ pagefile.sys PageFile大小2046 MB使用中35 MB Max使用35 MB注册表大小3 MB(当前),120 MB(最大)配置文件GUID {bef54e40-80cb-11e2-a600-806d6172696f}系统时钟间隔15 ms ----- [主板] ------- --------------------------------房地产价值制造商ASUSTeK COMPUTER INC。型号P8H61-M LX R2.0版本Rev X .0x序列号120801441113185北桥英特尔ID0100修订版09 Sout h Bridge Intel ID1C5C Revision 09 CPU Intel(R)Pentium(R)CPU G645 @ 2.90GHz Cpu插槽系统插槽4 PCI内存摘要最大容量16384 MBytes内存插槽2纠错无警告!无法保证DMI数据的准确性

我能做些什么才能实现此输出:

WITH PARALLEL AND SERIAL


----- [System Info] -----------------------------------------------------------

Property                  Value
Machine Type              AT/AT COMPATIBLE
Infrared (IR) Supported   No
DMI System UUID           809EC223-DAD7DD11-A2F33085-A993FFAC
UUID                      23C29E80-D7DA-11DD-A2F3-3085A993FFAC
Disk Space                Disk C: 89 GB Available, 97 GB Total, 89 GB Free
Disk Space                Disk D: 355 GB Available, 368 GB Total, 355 GB Free
Disk Space                Disk F: 274 MB Available, 3837 MB Total, 274 MB Free
Physical Memory           1724 MB Total, 1173 MB Free
Memory Load               31%
Virtual Memory            3619 MB Total, 3184 MB Free
PageFile Name             \??\C:\pagefile.sys
PageFile Size             2046 MB
In use                    35 MB
Max used                  35 MB
Registry Size             3 MB (current), 120 MB (maximum)
Profile GUID              {bef54e40-80cb-11e2-a600-806d6172696f}
The system clock interval 15 ms



----- [Motherboard] ---------------------------------------

Property         Value
Manufacturer     ASUSTeK COMPUTER INC.
Model            P8H61-M LX R2.0
Version          Rev X.0x
Serial Number    120801441113185
North Bridge     Intel ID0100 Revision 09
South Bridge     Intel ID1C5C Revision 09
CPU              Intel(R) Pentium(R) CPU G645 @ 2.90GHz
Cpu Socket       
System Slots     4 PCI
Memory Summary   
Maximum Capacity 16384 MBytes
Memory Slots     2
Error Correction None
Warning!         Accuracy of DMI data cannot be guaranteed

1 个答案:

答案 0 :(得分:2)

如果你是在浏览器中输出它,那么可能就是这种情况。如果您希望在浏览器中显示格式,则需要添加<pre>预格式标记:

echo '<pre>';
echo fread($myfile,filesize("baliwag_04162015.txt"));
echo '</pre>';

提示:你也可以查看view source,你会在那里看到它没关系。