daily pastebin goal
41%
SHARE
TWEET

PHP-XML

a guest Jan 29th, 2018 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     if (isset($_POST['fecha']) != "")
  3.         {
  4.             $fecha_previ = $_POST['fecha'];
  5.             $error = "nodia";
  6.                      
  7.             $previ_xml = simplexml_load_file("http://www.aemet.es/xml/municipios/localidad_46202.xml");
  8.             foreach ($previ_xml->prediccion->dia as $nodo)
  9.                 {
  10.                     $atributo_fecha = $nodo->attributes();
  11.                     $dia_fecha_xml = substr($atributo_fecha,8,2);
  12.                     $mes_fecha_xml = substr($atributo_fecha,5,2);
  13.                     $anyo_fecha_xml = substr($atributo_fecha,0,4);
  14.                     $atri_fecha_nuevo = $dia_fecha_xml."-".$mes_fecha_xml."-".$anyo_fecha_xml;                  
  15.                     #echo "FEcha del usuario :".$fecha_previ."<br>";
  16.                    #echo "Fecha modificada :".$atri_fecha_nuevo."<br>";
  17.                    
  18.                     if ($atri_fecha_nuevo == $fecha_previ)
  19.                         {
  20.                             $error = "noerror";
  21.                             foreach ($nodo->prob_precipitacion as $nodo_precipitacion)
  22.                             {
  23.                                 $atri_per_preci = $nodo_precipitacion->attributes();
  24.                                 if ($atri_per_preci['periodo'] == "00-24")
  25.                                     {
  26.                                          $prob_lluvia = $nodo_precipitacion;
  27.                                         }
  28.                             }
  29.                             foreach ($nodo->cota_nieve_prov as $nodo_cotanieve)
  30.                             {
  31.                                 $atri_per_cotanieve = $nodo_cotanieve->attributes();
  32.                                 $cotanieve = "No hay datos";
  33.                                 if ($atri_per_cotanieve['periodo'] == "00-24")
  34.                                     {
  35.                                         if ( $nodo_cotanieve != "")
  36.                                             {
  37.                                                 $cotanieve = $nodo_cotanieve;
  38.                                             }
  39.                                     }
  40.                             }    
  41.                             foreach ($nodo->estado_cielo as $nodo_estadocielo)
  42.                             {
  43.                                 $atri_estado_cielo = $nodo_estadocielo->attributes();
  44.                                 if ($atri_estado_cielo['periodo'] == "00-24")
  45.                                     {
  46.                                          $estadocielo = $nodo_estadocielo['descripcion'];
  47.                                     }
  48.                             }    
  49.  
  50.                         }
  51.                 }
  52.             if ($error=="noerror")
  53.                 {
  54.                     echo "<b>La previsión para el día $fecha_previ es la siguiente :</b><br>";
  55.                     echo "<b>Probabilidad de precipitación :</b> ". $prob_lluvia ."%<br>";
  56.                     echo "<b>La cota de nieve será de  :</b> ". $cotanieve."<br>";
  57.                     echo "<b>El estado del cielo será :</b>".$estadocielo."<br>";
  58.                 }
  59.             else
  60.                 {
  61.                     echo " No hay previsiones para ese día. Lo siento";
  62.                 }
  63.  
  64.         }
  65.     else
  66.         {
  67.            if (isset($_POST['submitbutton']))
  68.            {
  69.               echo "Por favor rellena el campo fecha" ;
  70.            }
  71.         }
  72. ?>
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top