SHARE
TWEET
PHP-XML
a guest
Jan 29th, 2018
38
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- <?php
- if (isset($_POST['fecha']) != "")
- {
- $fecha_previ = $_POST['fecha'];
- $error = "nodia";
- $previ_xml = simplexml_load_file("http://www.aemet.es/xml/municipios/localidad_46202.xml");
- foreach ($previ_xml->prediccion->dia as $nodo)
- {
- $atributo_fecha = $nodo->attributes();
- $dia_fecha_xml = substr($atributo_fecha,8,2);
- $mes_fecha_xml = substr($atributo_fecha,5,2);
- $anyo_fecha_xml = substr($atributo_fecha,0,4);
- $atri_fecha_nuevo = $dia_fecha_xml."-".$mes_fecha_xml."-".$anyo_fecha_xml;
- #echo "FEcha del usuario :".$fecha_previ."<br>";
- #echo "Fecha modificada :".$atri_fecha_nuevo."<br>";
- if ($atri_fecha_nuevo == $fecha_previ)
- {
- $error = "noerror";
- foreach ($nodo->prob_precipitacion as $nodo_precipitacion)
- {
- $atri_per_preci = $nodo_precipitacion->attributes();
- if ($atri_per_preci['periodo'] == "00-24")
- {
- $prob_lluvia = $nodo_precipitacion;
- }
- }
- foreach ($nodo->cota_nieve_prov as $nodo_cotanieve)
- {
- $atri_per_cotanieve = $nodo_cotanieve->attributes();
- $cotanieve = "No hay datos";
- if ($atri_per_cotanieve['periodo'] == "00-24")
- {
- if ( $nodo_cotanieve != "")
- {
- $cotanieve = $nodo_cotanieve;
- }
- }
- }
- foreach ($nodo->estado_cielo as $nodo_estadocielo)
- {
- $atri_estado_cielo = $nodo_estadocielo->attributes();
- if ($atri_estado_cielo['periodo'] == "00-24")
- {
- $estadocielo = $nodo_estadocielo['descripcion'];
- }
- }
- }
- }
- if ($error=="noerror")
- {
- echo "<b>La previsión para el día $fecha_previ es la siguiente :</b><br>";
- echo "<b>Probabilidad de precipitación :</b> ". $prob_lluvia ."%<br>";
- echo "<b>La cota de nieve será de :</b> ". $cotanieve."<br>";
- echo "<b>El estado del cielo será :</b>".$estadocielo."<br>";
- }
- else
- {
- echo " No hay previsiones para ese día. Lo siento";
- }
- }
- else
- {
- if (isset($_POST['submitbutton']))
- {
- echo "Por favor rellena el campo fecha" ;
- }
- }
- ?>
RAW Paste Data

