Jump to content

Looking for direction on PHP functions to learn/use to read display and compare data in multiple html files.


Recommended Posts

I am very much a novice with HTML and PHP and am looking for direction for the best approach to be able to read "table" data from multiple html files and display various elements as well as make comparisons, calculations, etc.  I have created spreadsheets in both Excel and Google that perform the same functions I'd like to duplicate and/or expand on in a web environment.

I have 26 weather stations that each use htx template files embedded with 120 x 2  data tags used to populate a 120 x 2 "table" of values in a html file.  These 26 files are recreated every 10 minutes as long as the software for each station is running.  An example of 1 of these 26 files can be seen here: 

http://wxvue.com/AzCoWx/Weather/WeatherLink/Images/AllVP2Tags.htm

With Excel, each one of these station files is imported into its own station worksheet and can then be referenced within other worksheets for display, comparisons, etc.  When the workbook is open, the data is refreshed every 10 minutes so the newest data from the 26 html files is read in.  Attached is an image showing a worksheet comparing several data elements between the 26 stations.  Where every html file contains the same data in the same order, I assume it is probably possible to read in only the rows I'm using as opposed to all data from all files as I am doing in Excel but either way works.

Initially, I'm looking for direction for the PHP functions I need to learn/use to best duplicate what I am doing with Excel, mainly just being able to access the various data in the 26 html files.

Any help and direction will be greatly appreciated. 

SRR1Wx26-AllVP2Tags.jpg

Edited by SWWeatherGuy

For parsing the HTML and extracting the data, look into DOMDocument.  Load the document, use getElementsByTagName to find the rows by grabbing the tr tags.  Then for each row, use getElementsByTagName to get the cells by grabbing the td tags.  Use textContent on the cells to extract the values.

  • Like 1

Alternatively, assuming they all have same rigid structure, ...

$fp = file('weather.html', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);

$data = [];

foreach ($fp as $line) {
    switch (substr($line, 0, 4)) {
        case '<!--' :
            if ($line[4]!=' ') {
                $section = substr($line, 4, -8);
            }
            break;
        case '<td>' :
            list($name, $value) = getData($line);
            $data[$section][$name] = $value;
            break;
        default :
            continue 2;
    }
}

function getData($line) {
    $l = substr($line, 4, -5);
    return explode('</td><td>', $l);
}

// View the results
echo '<pre>' . print_r($data, 1) . '</pre>';

giving ...

$data = Array
(
    [MISCELLANEOUS] => Array
        (
            [Name of Station] => AzureCove
            [City (from NOAA Setup)] => Garden City
            [State (from NOAA Setup)] => Utah
            [Elevation (from NOAA Setup)] =>  5954 ft
            [Latitude (from NOAA Setup)] =>  41° 56' 12" N
            [Longitude (from NOAA Setup)] => 111° 23' 20" W
            [Date on the PC] => 03/13/23
            [Time on the PC] =>  4:06a
            [UTC Time] => 10:06a
            [UTC Date] => 03/13/23
            [Date on the Station] => 03/13/23
            [Time on the Station] =>  4:05a
            [Sunrise Time] =>  7:41a
            [Sunset Time] =>  7:30p
            [Current Weather Forecast *] =>  Partly cloudy with little temperature change. 
            [Current Moon Phase] => Last Quarter 
            [EMC] => ---
            [EMC Unit] => %
            [Air Density] => 0.0842
            [Air Density Unit] => lb/cu.ft
        )

    [INSIDE TEMPERATURE] => Array
        (
            [Inside Temperature] => 42.5
            [High Inside Temperature] => 43.6
            [Time of High Inside Temperature] => 12:00a
            [Low Inside Temperature] => 42.5
            [Time of Low Inside Temperature] =>  3:41a
            [High Monthly Inside Temperature] => 45.4
            [Low Monthly Inside Temperature] => 39.4
            [High Yearly Inside Temperature] => 45.7
            [Low Yearly Inside Temperature] => 39.4
        )

    [OUTSIDE TEMPERATURE] => Array
        (
            [Outside Temperature] => 15.1
            [High Outside Temperature] => 21.7
            [Low Outside Temperature] => 15.1
            [Time of High Outside Temperature] => 12:00a
            [Time of Low Outside Temperature] =>  4:04a
            [High monthly Outside Temperature] => 46.1
            [Low monthly Outside Temperature] => -11.3
            [High yearly Outside Temperature] => 46.1
            [Low yearly Outside Temperature] => -12.5
        )

        .
        .
        .
)
   

 

  • Like 2
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.