Показать сообщение отдельно
  #2 (permalink)  
Старый 20.12.2022, 01:24
Новичок на форуме
Отправить личное сообщение для parshin Посмотреть профиль Найти все сообщения от parshin
 
Регистрация: 13.12.2022
Сообщений: 6

Есть идеально работающий php скрипт
<?php
    $city2_id="Perm"; // id города openweather.org
    $data_file2="http://api.openweathermap.org/data/2.5/weather?q=$city2_id&mode=xml&lang=ru&units=metric&appid=45aef403d21cba00f8464647a9595250"; // адрес xml файла
    $data_file2 = file_get_contents($data_file2,0); //получаем данные о погоде из xml файла
    $xml2 = new SimplexmlElement($data_file2); //помещаем данные в массив
    $city2= $xml2->city[name];//забиваем необходимые данные в переменные
    $temperature = $xml2->temperature[value];
    $feels_like = $xml2->feels_like[value];
    $weather_id = $xml2->weather[number];
    $weather_icon = $xml2->weather[icon];
    $weather_type = $xml2->weather[value];
    $pressure = $xml2->pressure[value];
    $humidity = $xml2->humidity[value];
    $sunrise = $xml2->city->sun[rise];
    $sunset = $xml2->city->sun[set];
    $windspeed = $xml2->wind->speed[value];
    $windcode = $xml2->wind->direction[code];
    $visibility = $xml2->visibility[value];
    if ($temperature > 0) {$temperature = '+'.$temperature;}
    $pressure = round($pressure * 0.750063755419211);
    $temperature = round($temperature);
    $feels_like = round($feels_like);
    date_default_timezone_set('Etc/GMT-5');
    $deff = strtotime($sunset) - strtotime($sunrise);
    $h_deff = floor($deff / 3600);
    $m_deff = floor(($deff - $h_deff * 3600) / 60);
    if ($pg == 0) $w_url = "weather/images/";
    if ($pg == 1) $w_url ="images/";
    if ($h_deff < 10) {$h_deff = '0'.$h_deff;}
    if ($m_deff < 10) {$m_deff = '0'.$m_deff;}
    $sunrise = date('H:i',strtotime("+5 hours", strtotime($sunrise)));
    $sunset = date('H:i',strtotime("+5 hours", strtotime($sunset)));
    $title2 = "Город: ".$city2."\n".$weather_type." ".$temperature."°C \nДавление: ".$pressure." мм рт. ст.\nВетер: ".$windcode." ".$windspeed." м/с \nВлажность: ".$humidity."%";
    $Day = date("d");
    $m = date("m");
    $Month = array (1 => "января",
                    2 => "февраля",
                    3 => "марта",
                    4 => "апреля",
                    5 => "мая",
                    6 => "июня",
                    7 => "июля",
                    8 => "августа",
                    9 => "сентября",
                   10 => "октября",
                   11 => "ноября",
                   12 => "декабря");
    $Year = date("Y");
    $w = date("w");
    $Week = array (0 => "воскресенье",
                   1 => "понедельник",
                   2 => "вторник",
                   3 => "среда",
                   4 => "четверг",
                   5 => "пятница",
                   6 => "суббота");
    $wind = array ( SW => "юго-западный",
                    SE => "юго-восточный",
                    NW => "северо-западный",
                    NE => "северо-восточный",
                    N => "северный",
                    S => "южный",
                    W => "западный",
                    E => "восточный",
                    WSW => "западно-юго-западный",
                    ESE => "восточно-юго-восточный",
                    SSW => "юго-юго-западный",
                    SSE => "юго-юго-восточный",
                    WNW => "западно-северо-западный",
                    ENE => "восточно-северо-восточный",
                    NNW => "северо-северо-западный",
                    NNE => "северо-северо-восточный");
?>

<div style="text-align: center;height: 290px;width: 350px;border-style: outset; border-width: 5px; background-color:#000000;">
    <table width='100%' height="100%" cellspasing='0' cellpadding='0'>
        <tr>
                <?php 
                echo '<td style="width: 100%;height: 100%;background-size: cover;background-image: url('.$w_url.'fon0.gif)">';
                ?>
                <font style="font-size: 18pt;text-align: center;font-weight: bold" color='#00FFFF'>
                    <p style="margin-bottom: 10px;margin-top: 2px"><?php echo $city2;?></p>
                </font>
                <font style="font-size: 14pt;color: #FFFFFF"><p style="margin-bottom: 2px;margin-top: 2px;text-align: center">
                <?php echo $Week[$w].'<br>'.$Day.' '.$Month[$m].' '.$Year.' <font face="LcdD">'.date("H:i").'</font><br>';?></font></p>
                <font style="font-size: 13pt;font-weight: bold" color='#FFFFFF'>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Погода: 
                    <?php
                        echo '<img width="32" height="32" src="'.$w_url.$weather_icon.'.png" alt="" title="'.$title2.'"> <font color="#FFFF00">'.$weather_type.'</font>';
                    ?>
                    <br>Температура: <font color='#FFFF00'><?php echo ($temperature."°C&nbsp;&nbsp;&nbsp;<font color='#FFFFFF'>По ощущению </font>".$feels_like."°C<br>");?></font></p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Давление: <font color='#FFFF00'><?php echo $pressure.' мм рт. ст.<br>';?></font></p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Ветер: <font color='#FFFF00'><?php echo $wind[trim($windcode)].' '.$windspeed.' м/с<br>';?></font></p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Влажность: <font color='#FFFF00'><?php echo $humidity.'%<br>';?></font></p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Видимость: <font color='#FFFF00'><?php echo $visibility.' м<br>';?></font></p>
                    <?php echo '<img src="'.$w_url.'01d.png" width="48" height="48" alt="" align="left">';?>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Рассвет: <font color='#FFFF00'><?php echo $sunrise.'&nbsp;&nbsp;&nbsp;';?></font>
                        Долгота дня: <font color='#FFFF00'><?php echo $h_deff.':'.$m_deff.'<br>';?></font>
                    </p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Закат: <font color='#FFFF00'><?php echo $sunset.'<br>';?></font></p>
                </font>
            </td>
        </tr>
    </table>
</div>

но он без автоматического обновления. Хотелось бы переделать его на javascript, но получается не совсем то, что нужно.
Ссылка http://pmm.h1n.ru/weather/ вверху php скрипт, внизу javascript.
Ответить с цитированием