Адаптация кона под php 5.4 и выше

R
На сайте с 01.12.2012
Offline
86
707

Всем привет.

При обновлении php пропал модуль погоды. С версией php 5.3.3 всё ок, ставлю выше 5.4 сразу выдаёт такую ошибку.

Warning: simplexml_load_file(http://export.yandex.ru/weather-ng/forecasts/26714.xml): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /home/virtwww/sait_ru/http/engine/modules/pogoda/weather.php on line 6 Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://export.yandex.ru/weather-ng/forecasts/26714.xml" in /home/virtwww/sait_ru/http/engine/modules/pogoda/weather.php on line 6 Warning: Invalid argument supplied for foreach() in /home/virtwww/sait_ru/http/engine/modules/pogoda/weather.php on line 11 

Подскажите в чём проблема и помогите адаптировать кон модуля под более раннею php

Модуль состоит из двух файлов

<?php require_once 'weather.php' ;


$w_city_id = 26714;
// Идентификатор города - можно узнать по адресу http://weather.yandex.ru/static/cities.xml

$col = 1 ;
// количество дней, на сколько нужен прогноз

$day_of_the_week_array = array(
1 => '<span>в понедельник</span>',
2 => '<span>во вторник</span>',
3 => '<span>в среду</span>',
4 => '<span>в четверг</span>',
5 => '<span>в пятницу</span>',
6 => '<span>в субботу</span>',
7 => '<span>в воскресенье</span>'
); // Массив дней недели (для вывода)

$time_of_day = array(
0 => 'утро',
1 => 'день',
2 => 'вечер',
3 => 'ночь'
); // Массив времени суток (для вывода)

$wind = array(
's' => 'южн.',
'e' => 'вос.',
'n' => 'сев.',
'w' => 'зап.',
'se' => 'ю-в',
'sw' => 'ю-з',
'ne' => 'с-в',
'nw' => 'с-з',
) ;

$out = get_weather($w_city_id, $col, $day_of_the_week_array, $time_of_day) ;

/* заполняем масив при помощи функции, первый параметр обязательный - индентификатор города
другие параметры необязательны - в этом случае используется значения по умолчанию */
?>

<?php foreach ($out as $key => $value) { ?>
<div class="poggl"><p><a href="/pogoda/3995-gusev.html">Погода в Гусеве »</a></p>
<?php echo $value['day']; ?>.<?php echo $value['month']; ?>.<?php echo $value['year']; ?> <?php echo $value['day_of_week']; ?></div>
<?php foreach ($value['weather'] as $key1 => $value1) { ?>
<div class="pogpere"><p><?php echo $value1['time_of_day']; ?><img src="http://yandex.st/weather/1.1.78/i/icons/30x30/<?php echo $value1['image']; ?>.png" width="30" height="30" alt="" /><?php echo $value1['temp_from'] ; ?> ... <?php echo $value1['temp_to'] ; ?></p>
<?php echo $value1['wind_speed'] ; ?> м/с <?php echo $wind[(string)$value1['wind_direction']] ; ?>, <?php echo $value1['pressure'] ; ?> мм рт. ст.</div>
<?php } ?>
<?php } ?>

<?php


function get_weather ($city, $col = 10, $day_of_the_week_array = array(1 => 'пн', 2 => 'вт', 3 => 'ср', 4 => 'чт', 5 => 'пт', 6 => 'сб', 7 => 'вс'), $time_of_day = array(0 => 'утро', 1 => 'день', 2 => 'вечер', 3 => 'ночь')) {

$data_file = 'http://export.yandex.ru/weather-ng/forecasts/'.$city.'.xml'; // Загружаем файл прогноза погоды для выбранного города
$xml = simplexml_load_file($data_file); // загружаем xml файл через simple_xml

$out = array(); // Массив вывода прогноза
$counter = 0 ; // Счетчик количества дней, для которых доступен прогноз

foreach ( $xml->day as $day ) {

if ($counter == $col) {break;}

$get_date = explode ("-" , $day['date']) ;
$day_of_week = date("N", mktime(0, 0, 0, $get_date[1], $get_date[2], $get_date[0])) ;

$out[$counter]['day'] = $get_date[2] ;
$out[$counter]['month'] = $get_date[1] ;
$out[$counter]['year'] = $get_date[0] ;
$out[$counter]['day_of_week'] = $day_of_the_week_array[$day_of_week] ;

for ($i=0;$i<=3;$i++) {

if($day->day_part[$i]->temperature == '') {

$get_temp_from = $day->day_part[$i]->temperature_from;
$get_temp_to = $day->day_part[$i]->temperature_to;
$get_wind_speed = $day->day_part[$i]->wind_speed;
$get_wind_direction = $day->day_part[$i]->wind_direction;
$get_weather_type = $day->day_part[$i]->weather_type;
$get_weather_type = iconv('UTF-8', 'windows-1251', $get_weather_type);
$get_humidity = $day->day_part[$i]->humidity;
$get_pressure = $day->day_part[$i]->pressure;
$get_avg = $day->day_part[$i]->{'temperature-data'}->avg;

} else {

$get_temp_from = (integer)$day->day_part[$i]->temperature-1 ;
$get_temp_to = (integer)$day->day_part[$i]->temperature+1 ;

}

if($get_temp_from>0 ) {$get_temp_from = '+'.$get_temp_from ; }
if($get_temp_to>0 ) {$get_temp_to = '+'.$get_temp_to ; }
$out[$counter]['weather'][$i]['temp_from'] = $get_temp_from;
$out[$counter]['weather'][$i]['temp_to'] = $get_temp_to;
$out[$counter]['weather'][$i]['image'] = $day->day_part[$i]->{'image-v3'};
$out[$counter]['weather'][$i]['time_of_day'] = $time_of_day[$i] ;
$out[$counter]['weather'][$i]['wind_speed'] = $get_wind_speed ;
$out[$counter]['weather'][$i]['wind_direction'] = $get_wind_direction ;
$out[$counter]['weather'][$i]['weather_type'] = $get_weather_type;
$out[$counter]['weather'][$i]['humidity'] = $get_humidity;
$out[$counter]['weather'][$i]['pressure'] = $get_pressure;
$out[$counter]['weather'][$i]['avg'] = $get_avg;



} $counter++ ;
}

return $out ;

}?>

Заранее признателен всем за подсказку.

siv1987
На сайте с 02.04.2009
Offline
427
#1

simplexml_load_string(file_get_contents('http://export.yandex.ru/weather-ng/forecasts/26714.xml'))

R
На сайте с 01.12.2012
Offline
86
#2
siv1987:
simplexml_load_string(file_get_contents('http://export.yandex.ru/weather-ng/forecasts/26714.xml'))

А можно поподробнее немного

Это где-то добавить, или заменить что-то?

Gerga
На сайте с 02.08.2015
Offline
94
#3
Radrigo:
$xml = simplexml_load_file($data_file); // загружаем xml файл через simple_xml


simplexml_load_string(file_get_contents($data_file)); // загружаем xml файл через simple_xml
R
На сайте с 01.12.2012
Offline
86
#4

Gerga

Проблема не исчезла, но ошибка поменялась

было

Warning: simplexml_load_file(http://export.yandex.ru/weather-ng/forecasts/26714.xml): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /home/virtwww/w_forum-gusev-o_93c674e2/http/pogoda/weather.php on line 6 Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://export.yandex.ru/weather-ng/forecasts/26714.xml" in /home/virtwww/w_forum-gusev-o_93c674e2/http/pogoda/weather.php on line 6 Warning: Invalid argument supplied for foreach() in /home/virtwww/w_forum-gusev-o_93c674e2/http/pogoda/weather.php on line 11 

стало

Warning: file_get_contents(http://export.yandex.ru/weather-ng/forecasts/26714.xml): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /home/virtwww/w_forum-gusev-o_93c674e2/http/pogoda/weather.php on line 6 Warning: Invalid argument supplied for foreach() in /home/virtwww/w_forum-gusev-o_93c674e2/http/pogoda/weather.php on line 11 
ПЗ
На сайте с 10.10.2006
Offline
92
#5

проверьте значение allow_url_fopen в phpinfo()

Автомобили в России (http://www.autobb.ru/). Спецтехника BIZ - вся строительная, дорожная, коммунальная техника (http://www.spectehnika.biz/) и другая спецтехника в одном месте.
R
На сайте с 01.12.2012
Offline
86
#6
Павел Зотов:
проверьте значение allow_url_fopen в phpinfo()

allow_url_fopen On

А должно выть включено, или выключено?

siv1987
На сайте с 02.04.2009
Offline
427
#7
Radrigo:
стало

Есть подозрение что вас забанили. Либо вы нам не тот адрес показываете который запрашиваете.

R
На сайте с 01.12.2012
Offline
86
#8

Проблема решена.

дело не в php было, а в сервере, при переносе сайта на другой сервер, проблема решилась. Для другого сервера яндекс возвращает результат запроса без проблем.

siv1987
На сайте с 02.04.2009
Offline
427
#9
Radrigo:
дело не в php было, а в сервере

а точнее не в сервере, а в IP.

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий