シンプルな天気ウィジェット

最近、私は小さな天気ウィジェットをサイトに投稿する必要がありました。これらのオプションは、ギスメテオで提供されたオプションが適合しませんでした。

インターネットでの長い検索の後、gismeteoを送信するxmlコードを解析するためのいくつかのオプションが見つかりましたが、それらはすべて非常に複雑でわかりにくいものでした...

私は自分で書かなければならなかった))私の意見では、それは非常にエレガントに判明しました...誰かが便利になる可能性があります。



$ url = 'http://informer.gismeteo.ru/xml/27612_1.xml';

$ content = file_get_contents($ url);

$ xml = simplexml_load_string($コンテンツ);

$ tod_array = array( 'night'、 'morning'、 'day'、 'evening');

$ rumb_array = array( 'C'、 'C​​B'、 'B'、 'SE'、 'Yu'、 'SW'、 'Z'、 'SZ');

$ text = '';

if($ xml){

$ text。= '<div class = "block-head red"> <h3> <a href="#">天気予報</a> </ h3> </ div> <div class = "iTable"> <テーブルの幅= "100%"> ';

foreach($ xml-> REPORT-> TOWN-> $値として予測){

$ 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>利用できない情報</ b>';

}

echo $ text;

私のブログからクロスポスト



All Articles