Posted: . At: 10:20 AM. This was 8 months ago. Post ID: 18440
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


My Australian radio and TV website updated.


I have updated my radio and TV application on my website. This now has a nice EPG that allows the display of all upcoming programs by state and will be very useful for keeping track of all of your favorite TV programs. See it here: https://www.securitronlinux.com/radio/epg.php. This is using PHP to parse an XML file and then display the results thusly. This is part of the radio and TV web application I created, This allows the listing of all radio and TV streams for any TV station you wish to watch. See the main application here: https://securitronlinux.com/radio/index.php. I have updated it with a nice CSS grid layout to fit as many items on the screen as possible. I think it looks very nice indeed. This is parsing a JSON file and then printing the output in a very nice format. I am very proud of this application and I hope it is very useful. Parsing JSON can be very tricky, especially when you need to parse a section below the current section you are printing. But this can be done eventually with some creative code.

Here is an example.

programs.php
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
foreach ($json as $key => $value) {
    if (!is_array($value)) {
        echo '<p>', $key . '=>' . $value . '</p>';
    } else {
        echo '<img src="', $value['logo'] . '" width="192" alt="" class="img1"/>';
        echo '<p>',  $value['name'] . '&nbsp;';
        echo '<p>',  $value['description'] . '&nbsp;';
        echo '<br />', '<a href="' . $value['mjh_master'] . '">' . $value['mjh_master'] .'</a>' . '</p>';
 
        // Check if 'programs' is present and is an array
        if (isset($value['programs']) && is_array($value['programs'])) {
            // Iterate through the 'programs' array
            foreach ($value['programs'] as $program) {
                echo '<p>', $program['program_name'] . ': ' . $program['program_description'] . '</p>';
                // Add more properties as needed
            }
        }
    }
}

This is therefore very easy, it will print a section of JSON as shown below.

mjh-10-nsw	{}
mjh-10bold-nsw	
chno	12
epg_id	"mjh-10bold-nsw"
headers	{}
logo	"https://i.mjh.nz/.images/10bold-nsw.png"
mjh_master	"https://i.mjh.nz/10bold-nsw.m3u8"
name	"10 BOLD"
network	"Ten"
programs	
0	
0	1694475262
1	"Jake and the Fatman"
1	
0	1694478931
1	"JAG"
2	
0	1694482476
1	"JAG"
3	
0	1694486022
1	"In the Dark"
4	
0	1694489556
1	"Bull"
5	
0	1694493122
1	"Jake and the Fatman"
6	[]
7	[]
8	[]
9	[]
10	[]
mjh-10peach-nsw	{}
mjh-10shake-nsw	{}
mjh-7afl-FAST	{}
mjh-7bravo-FAST	{}
mjh-7flix-syd	{}
mjh-7mate-syd	{}
mjh-7now-FAST	{}
mjh-7two-syd	{}

The “programs” section is below the section I was printing and then I had to add extra code to print this along with the existing content.

        // Check if 'programs' is present and is an array
        if (isset($value['programs']) && is_array($value['programs'])) {
            // Iterate through the 'programs' array
            foreach ($value['programs'] as $program) {
                echo '<p>', $program['program_name'] . ': ' . $program['program_description'] . '</p>';
                // Add more properties as needed
            }
        }

This was very easy.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.