Opening a Text File using PHP - Fixing the Format

549

Basically, my text file contains this info:


However using this code in PHP to open it:

{-code-2}

I get something like this:

WITH PARALLEL AND SERIAL ----- [System Info]

582

Answer

--------- 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]
916

Answer

--------- 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

What can I do so that I can achieve this output:

WITH PARALLEL AND SERIAL


----- [System Info]
270

Answer

--------- 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]
861

Answer

--------- 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 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 ----- [System Info]
458

Answer

--------- 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]
980

Answer

--------- 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
312

Answer

Solution:

If you're outputting it in a browser, yeah that would be likely the case. If you want the formatting following inside the browser showing it, you'll need to add a<pre> pre format tag:

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

Hint: You can also check out theview source and you'll see it there its okay.

People are also looking for solutions to the problem: php - Is it a good practice to define expectation in dataProvider

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.