Поддержка Проблемы и решения Не работает парсинг погоды через XML

  • Не парсит погоду только в wp, на openserver проверил, все работает. Значит проблема не в парсинге. Где что изменить в WP чтобы все заработало? Спасибо.

Просмотр 4 ответов — с 1 по 4 (всего 4)
  • <?php 
    $pogoda = file_get_contents('https://export.yandex.ru/bar/reginfo.xml?region=$city_10646.xml'); 
    preg_match('/<weather_type>(.*?)<\/weather_type>/i',$pogoda,$type); 
    preg_match('/<temperature class_name="t4" color="F1F0E9">(.*?)<\/temperature>/i',$pogoda,$temp); 
    preg_match('/<image-v3 size="48">(.*?)<\/image-v3>/i',$pogoda,$img2); 
    $vivod = "<img align=\"top\" src=\"$img2[1]\" alt=\"$type[1]\" />$temp[1] °C 
    $type[1] ";
    echo $vivod; 
    ?>
    Модератор Yui

    (@fierevere)

    永子

    и куда был вставлен этот код?

    Не работает как в header так и в теле статьи при установленном плагине exec-php. Вообщем не знаю на что думать. Вот курсы валют без проблем спарсились. Вот собственно код парсинга валют для сравнения `<?php
    $cache_lifetime = 3600; //в секундах, 3600=1 час
    $cache_file = «cache/cache.html»; // в папке cache будет создаваться закешированный файл cache.html
    $cache_content = false;
    if ( file_exists($cache_file) ) {
    $cache_modified = time() — @filemtime($cache_file);
    if ( $cache_modified < $cache_lifetime ) {
    $cache_content = file_get_contents($cache_file);
    }}

    $date = date(«d.m.Y»); // Сегодня
    $dom = new domDocument(«1.0», «cp1251»);
    $dom->loadXML(file_get_contents(«http://www.cbr.ru/scripts/XML_daily.asp?date_req=$date&#187;));
    $root = $dom->documentElement;
    $childs = $root->childNodes;
    $data = array();
    for ($i = 0; $i < $childs->length; $i++) {
    $childs_new = $childs->item($i)->childNodes;
    for ($j = 0; $j < $childs_new->length; $j++) {
    $el = $childs_new->item($j);
    $code = $el->nodeValue;
    // Указываем нужные нам валюты, полный список их можно получить в файле http://www.cbr.ru/scripts/XML_daily.asp?date_req= в поле <CharCode>…</CharCode>
    if ( $cache_content === false ) { ob_start();
    $cache_content = $content;
    ob_end_clean();
    $fp = @fopen($cache_file, «w»);
    if ( $fp ) {
    @fwrite($fp, $cache_content);
    @fclose($fp);
    }}
    echo $cache_content;

    if (($code == «USD») || ($code == «EUR»)) $data[] = $childs_new;
    }
    }
    for ($i = 0; $i < count($data); $i++) {
    $list = $data[$i];
    for ($j = 0; $j < $list->length; $j++) {
    $el = $list->item($j);
    if ($el->nodeName == «CharCode») echo $el->nodeValue.» — «;
    elseif ($el->nodeName == «Value») echo $el->nodeValue.»<br />»;
    }
    }
    ?>`

    Ваш скрипт полностью рабочий.
    вот смотрите сами: http://test.wpgear.xyz/ok.php

    Возможно, что вас просто источник забанил.

    • Ответ изменён 7 лет, 5 месяцев назад пользователем wpgear.
Просмотр 4 ответов — с 1 по 4 (всего 4)
  • Тема «Не работает парсинг погоды через XML» закрыта для новых ответов.