Recently, I needed to place on the site a small weather informer, the options that are offered on the gismeteo did not fit.
After a long search on the Internet, several options were found to parse the xml code that transmits the gismeteo, but they were all very complicated and confusing ...
I had to write my own)) it turned out in my opinion quite elegant ... can someone come in handy.
$ url = 'http: //informer.gismeteo.ru/xml/27612_1.xml';
$ content = file_get_contents ($ url);
$ xml = simplexml_load_string ($ content);
$ tod_array = array ('night', 'morning', 'day', 'evening');
$ rumb_array = array ('C', 'SV', 'B', 'YuV', 'Yu', 'YuZ', 'Z', 'N3');
$ text = '';
if ($ xml) {
$ text. = '<div class = "block-head red"> <h3> <a href="#"> Weather forecast </a> </ h3> </ div> <div class = "iTable"> < table width = "100%"> ';
foreach ($ xml-> REPORT-> TOWN-> FORECAST as $ value) {
$ tod = (int) $ value-> attributes () -> tod;
$ text. = '<tr> <td>'. $ tod_array [$ tod]. '</ td> <td>'. (int) $ value-> TEMPERATURE-> attributes () -> min. ' - '. (Int) $ value-> TEMPERATURE-> attributes () -> max.' ° C </ td> <td> '. (Int) $ value-> WIND-> attributes () -> min.' - '. (Int) $ value-> WIND-> attributes () -> max.' m \ s'. $ rumb_array [(int) $ value-> WIND-> attributes () -> direction]. '</ td> </ tr>';
}
$ text. = '</ table> </ div>';
} else {
$ text. = '<b> Information not available </ b>';
}
echo $ text;
Is a crosspost from my blog