Data into Array displayed in table

Hi there, I might have posted this message before in the under the wrong page, i hope this is the right one.

I am facing a problem makin a php script for my education as a hydrographer.

I need to load data.txt (attached) file in to array which is shown by a table with 2 lists. a part of the data file looks like this:

                          :00      :10      :20      :30      :40      :50
           15:00       68       84       99      113      126      130
           16:00      147      156      163      168      172      175
           17:00      177      177      177      174      171      167

The 15:00 and :10 for example are showing a measured value of 68 at 15:10. So i hope its possible for somewan to make a script that can read the txt file that is attached and can make the data shown in a table with 1 array showing the time and another showing the meassured value.

I already made some kind of interface which is able to show the data.txt file in PHP(Attached). So the next step is to get the right data out of the file (date time)array, (meassured value)array into a table shown like.

time value
15:00 68
15:10 84
15:20 99

etc.

I hope somewan can help me with this problem because i am stuck at the moment with to less time and knowledge.

p.s. I use wampserver to run a localhost


interface.txt (332 Bytes)

data.txt (3.45 KB)

Well, there are many ways to do this process.
The easiest is to use string functions which allows you to break down inputs.

Assuming that your data is always in the same format as your sample, you can read it one line
at a time instead of all at once. At each line, you would have to figure out which lines contain
your data and then, just pull out what you need. Once you have it, you can display it as needed.

So, here is some reading for you. First, you need how to read txt files.
http://www.w3schools.com/php/func_filesystem_fgets.asp
(Note that example #2 shows how to read your file one line at a time…)

Then, for each line, you would have to check to see if it was a title line or data line.
If a data line where the numbers are that you need to pull out, you would have to capture
the data into variables. You know they are set positions as they are lined up, so, you just
need to loop thru the line pulling out those positions. You can use the substr function for that.
http://www.w3schools.com/php/func_string_substr.asp

With the substr function, you can steal columns of data. Just remember to split them up in the
middle of the blank cols. (look for the largest width of data) And, you can use the trim() function
to trim off any spaces. Loosely like $col5=trim(substr($line_input, 40)) Or something similar. You
would need to pull all of the items out of each line using substr, trim it and save it into an array.
Run thru the entire file placing them into a two-dimensional array and use that to display the data
back when you need it…

Well, there you go. Hope that gets you started. If you get stuck, let us know…

Sponsor our Newsletter | Privacy Policy | Terms of Service