使用 PHP 打开文本文件 - 修复格式
Opening a Text File using PHP - Fixing the Format
基本上,我的文本文件包含以下信息:
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);
}
?>
我得到这样的结果:
并行和串行 ----- [系统信息] -------------------------------- -------------------------- 属性 值机器类型 AT/AT 兼容红外 (IR) 支持 无 DMI 系统 UUID 809EC223-DAD7DD11-A2F33085-A993FFAC UUID 23C29E80-D7DA-11DD-A2F3-3085A993FFAC 磁盘 Space 磁盘 C:可用 89 GB,总计 97 GB,可用磁盘 89 GB Space 磁盘 D:可用 355 GB,总计 368 GB,可用磁盘 355 GB Space 磁盘 F:可用空间 274 MB,总计 3837 MB,可用物理内存 274 MB 总计 1724 MB,可用内存负载 1173 MB 31% 虚拟内存 总计 3619 MB,可用页面文件 3184 MB名称 \??\C:\pagefile.sys 页面文件大小 2046 MB 使用中 35 MB 最大使用 35 MB 注册表大小 3 MB(当前),120 MB(最大) 配置文件 GUID {bef54e40-80cb-11e2-a600-806d6172696f } 系统时钟间隔15ms ----- [Motherboard] ---------------------------------- ---- 属性 Value Manufacturer ASUSTeK COMPUTER INC. 型号 P8H61-M LX R2.0 Version Rev X.0x Serial Number 120801441113185 North Bridge Intel ID0100 Revision 09 South B ridge Intel ID1C5C Revision 09 CPU Intel(R) Pentium(R) CPU G645 @ 2.90GHz Cpu 套接字系统插槽 4 PCI 内存摘要最大容量 16384 MBytes 内存插槽 2 纠错 None 警告!无法保证 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
如果您在浏览器中输出它,是的,很可能就是这种情况。如果您希望浏览器中显示以下格式,您需要添加一个 <pre>
预格式化标签:
echo '<pre>';
echo fread($myfile,filesize("baliwag_04162015.txt"));
echo '</pre>';
提示:您也可以查看 view source
,您会在那里看到它没问题。
基本上,我的文本文件包含以下信息:
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);
}
?>
我得到这样的结果:
并行和串行 ----- [系统信息] -------------------------------- -------------------------- 属性 值机器类型 AT/AT 兼容红外 (IR) 支持 无 DMI 系统 UUID 809EC223-DAD7DD11-A2F33085-A993FFAC UUID 23C29E80-D7DA-11DD-A2F3-3085A993FFAC 磁盘 Space 磁盘 C:可用 89 GB,总计 97 GB,可用磁盘 89 GB Space 磁盘 D:可用 355 GB,总计 368 GB,可用磁盘 355 GB Space 磁盘 F:可用空间 274 MB,总计 3837 MB,可用物理内存 274 MB 总计 1724 MB,可用内存负载 1173 MB 31% 虚拟内存 总计 3619 MB,可用页面文件 3184 MB名称 \??\C:\pagefile.sys 页面文件大小 2046 MB 使用中 35 MB 最大使用 35 MB 注册表大小 3 MB(当前),120 MB(最大) 配置文件 GUID {bef54e40-80cb-11e2-a600-806d6172696f } 系统时钟间隔15ms ----- [Motherboard] ---------------------------------- ---- 属性 Value Manufacturer ASUSTeK COMPUTER INC. 型号 P8H61-M LX R2.0 Version Rev X.0x Serial Number 120801441113185 North Bridge Intel ID0100 Revision 09 South B ridge Intel ID1C5C Revision 09 CPU Intel(R) Pentium(R) CPU G645 @ 2.90GHz Cpu 套接字系统插槽 4 PCI 内存摘要最大容量 16384 MBytes 内存插槽 2 纠错 None 警告!无法保证 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
如果您在浏览器中输出它,是的,很可能就是这种情况。如果您希望浏览器中显示以下格式,您需要添加一个 <pre>
预格式化标签:
echo '<pre>';
echo fread($myfile,filesize("baliwag_04162015.txt"));
echo '</pre>';
提示:您也可以查看 view source
,您会在那里看到它没问题。