3v4l.org

run code in 300+ PHP versions simultaneously
<?php $var1 = array(0=>"Temp min."); $var2 = array(0=>"Temp max."); $var3 = array(0=>"Wind."); $var4 = array(0=>"Symbol."); $var5 = array(0=>"Day."); $array = array(); //if (!empty($_POST['file'])) echo 'fichero lleno'; //else echo 'fichero vacio'; if (isset($_POST['file']) and (!empty($_POST['file']))) { $file = $_POST['file']; // We recover the file data to treat if($xml = simplexml_load_file($file)){ $i=0; $nday=7; // Here is the forecast for 7 days $url= $xml->location->interesting->url; $array=explode('-', $url); foreach ($xml->location->var as $var) { switch ($i) { case 0: $j=0; for($j=0; $j<$nday; $j++){$var1 = $var1 + array($j+1=>htmlentities($xml->location->var[$i]->data->forecast[$j]->attributes()->value,ENT_COMPAT,'UTF-8'));} break; case 1: $j=0; for($j=0; $j<$nday; $j++){$var2 = $var2 + array($j+1=>htmlentities($xml->location->var[$i]->data->forecast[$j]->attributes()->value,ENT_COMPAT,'UTF-8'));} break; case 2: $j=0; for($j=0; $j<$nday; $j++){$var3 = $var3 + array($j+1=>htmlentities($xml->location->var[$i]->data->forecast[$j]->attributes()->value,ENT_COMPAT,'UTF-8'));} break; case 3: $j=0; for($j=0; $j<$nday; $j++){$var4 = $var4 + array($j+1=>htmlentities($xml->location->var[$i]->data->forecast[$j]->attributes()->value,ENT_COMPAT,'UTF-8'));} break; case 4: $j=0; for($j=0; $j<$nday; $j++){$var5 = $var5 + array($j+1=>htmlentities($xml->location->var[$i]->data->forecast[$j]->attributes()->value,ENT_COMPAT,'UTF-8'));} break; }//switch $i++; }//foreach }//if else { echo "Enter the URL path of the XML file"; } //We will build a table to display the results $i=1; echo '<br><br>'; echo '<table height="240px" width="635px" class="table_background">'; echo '<tr>'; echo '<th colspan="7">'; echo 'Forecasts for '.$array[3]; echo '</th>'; echo '</tr>'; echo '<tr>'; for($i=1; $i<$nday+1; $i++){ echo '<td>'; echo'<table height="195px" width="80px" class="file_background">'; echo'<tr>'; echo '<th>'; echo " ".$var5[$i]; echo '</th>'; echo '</tr>'; if (isset($var4[$i])){ echo '<tr>'; echo '<td align="center">'; if ($var4[$i] == "Sunny") {echo " <img src='./images/weather/1.gif' alt='Sunny' title='Sunny'/><BR>";} if ($var4[$i] == "Cloudy Intervals"){echo " <img src='./images/weather/2.gif' alt ='Cloudy Intervals' title='Cloudy Intervals'/><BR>";} if ($var4[$i] == "Cloudy Skies") {echo " <img src='./images/weather/3.gif' alt = 'Cloudy Skies' title='Cloudy Skies'/><BR>";} if ($var4[$i] == "Overcast") {echo " <img src='./images/weather/4.gif' alt = 'Overcast' title='Overcast'/><BR>";} if ($var4[$i] == "Cloudy intervals with light rain") {echo " <img src='./images/weather/5.gif' alt='Cloudy intervals with light rain' title='Cloudy intervals with light rain'/><BR>";} if ($var4[$i] == "Cloudy with light rain") {echo " <img src='./images/weather/6.gif' alt='Cloudy with light rain title='Cloudy with light rain'/><BR>";} if ($var4[$i] == "Overcast with light rain") {echo " <img src='./images/weather/7.gif' alt='Overcast with light rain' title='Overcast with light rain'/><BR>";} if ($var4[$i] == "Cloudy intervals with moderate rain") {echo " <img src='./images/weather/8.gif' alt='Cloudy intervals with moderate rain' title='Cloudy intervals with moderate rain'/><BR>";} if ($var4[$i] == "Cloudy with moderate rain") {echo " <img src='./images/weather/9.gif' alt='Cloudy with moderate rain' title='Cloudy with moderate rain'/><BR>";} if ($var4[$i] == "Overcast with moderate rain") {echo " <img src='./images/weather/10.gif' alt='Overcast with moderate rain' title='Overcast with moderate rain'/><BR>";} if ($var4[$i] == "Cloudy intervals with thunderstorms") {echo " <img src='./images/weather/11.gif' alt='Cloudy intervals with thunderstorms' title='Cloudy intervals with thunderstorms'/><BR>";} if ($var4[$i] == "Cloudy with thunderstorms") {echo " <img src='./images/weather/12.gif' alt='Cloudy with thunderstorms' title='Cloudy with thunderstorms'/><BR>";} if ($var4[$i] == "Overcast with thunderstorms") {echo " <img src='./images/weather/13.gif' alt='Overcast with thunderstorms' title='Overcast with thunderstorms'/><BR>";} if ($var4[$i] == "Cloudy intervals, thunderstorms and hail") {echo " <img src='./images/weather/14.gif' alt='Cloudy intervals, thunderstorms and hail' title='Cloudy intervals, thunderstorms and hail'/><BR>";} if ($var4[$i] == "Cloudy, thunderstorms and hail") {echo " <img src='./images/weather/15.gif' alt='Cloudy, thunderstorms and hail' title='Cloudy, thunderstorms and hail'/><BR>";} if ($var4[$i] == "Overcast, thunderstorms and hail"){echo " <img src='./images/weather/16.gif' alt ='Overcast, thunderstorms and hail' title='Overcast, thunderstorms and hailo'/><BR>";} if ($var4[$i] == "Cloudy intervals and snow") {echo " <img src='./images/weather/17.gif' alt='Cloudy intervals and snow' title='Cloudy intervals and snow'/><BR>";} if ($var4[$i] == "Cloudy and snow"){echo " <img src='./images/weather/18.gif' alt='Cloudy and snow' title='Cloudy and snow'/><BR>";} if ($var4[$i] == "Overcast an snow"){echo " <img src='./images/weather/19.gif' alt='Overcast an snow' title='Overcast an snow'/><BR>";} echo '</td>'; echo '</tr>'; } //fi if $var4[$i] //echo '</tr>'; echo '<tr>'; echo '<th>'; echo " Min ".$var1[$i]; echo '</th>'; echo '</tr>'; echo '<tr>'; echo '<th>'; echo " Max ".$var2[$i]; echo '</th>'; echo '</tr>'; if (isset($var3[$i])){ echo '<tr>'; echo '<td align="center">'; if ($var3[$i] == "Light N wind") {echo " <img src='./images/wind/WindN.png' alt='Light N Wind' title='Light N Wind'/><BR>";} if ($var3[$i] == "Light NE wind") {echo " <img src='./images/wind/WindNE.png' alt='Light NE wind' title='Light NE wind'/><BR>";} if ($var3[$i] == "Light E wind") {echo " <img src='./images/wind/WindE.png' alt='Light E wind' title='Light E wind'/><BR>";} if ($var3[$i] == "Light SE wind") {echo " <img src='./images/wind/WindSE.png' alt='Light SE wind' title='Light SE wind'/><BR>";} if ($var3[$i] == "Light S wind") {echo " <img src='./images/wind/WindS.png' alt='Light S wind' title='Light S wind'/><BR>";} if ($var3[$i] == "Light SW wind") {echo " <img src='./images/wind/WindSW.png' alt='Light SW wind' title='Light SW wind'/><BR>";} if ($var3[$i] == "Light W wind") {echo " <img src='./images/wind/WindW.png' alt='Light W wind' title='Light W wind'/><BR>";} if ($var3[$i] == "Light NW wind") {echo " <img src='./images/wind/WindNW.png' alt='Light NW wind' title='Light NW wind'/><BR>";} if ($var3[$i] == "Moderate N wind") {echo " <img src='./images/wind/WindN.png' alt='Moderate N wind' title='Moderate N wind'/><BR>";} if ($var3[$i] == "Moderate NE wind") {echo " <img src='./images/wind/WindNE.png' alt='Moderate NE wind' title='Moderate NE wind'/><BR>";} if ($var3[$i] == "Moderate E wind") {echo "<img src='./images/wind/WindE.png' alt='Moderate E wind' title='Moderate E wind'/><BR>";} if ($var3[$i] == "Moderate SE wind") {echo " <img src='./images/wind/WindSE.png' alt='Moderate SE wind' title='Moderate SE wind'/><BR>";} if ($var3[$i] == "Moderate S wind") {echo " <img src='./images/wind/WindS.png' alt='Moderate S wind' title='Moderate S wind'/><BR>";} if ($var3[$i] == "Moderate SW wind") {echo " <img src='./images/wind/WindSW.png' alt='Moderate SW wind' title='Moderate SW wind'/><BR>";} if ($var3[$i] == "Moderate W wind") {echo " <img src='./images/wind/WindW.png' alt='Moderate W wind' title='Moderate W wind'/><BR>";} if ($var3[$i] == "Moderate NW wind") {echo " <img src='./images/wind/WindNW.png' alt='Moderate NW wind' title='Moderate NW wind'/><BR>";} if ($var3[$i] == "Wind N wind") {echo " <img src='./images/wind/WindN.png' alt='Wind N wind' title='Wind N wind'/><BR>";} if ($var3[$i] == "Wind NE wind") {echo " <img src='./images/wind/WindNE.png' alt='Wind NE wind' title='Wind NE wind'/><BR>";} if ($var3[$i] == "Wind E wind") {echo " <img src='./images/wind/WindE.png' alt='Wind E wind' title='Wind E wind'/><BR>";} if ($var3[$i] == "Wind SE wind") {echo " <img src='./images/wind/WindSE.png' alt='Wind SE wind' title='Wind SE wind'/><BR>";} if ($var3[$i] == "Wind S wind") {echo " <img src='./images/wind/WindS.png' alt='Wind S wind' title='Wind S wind'/><BR>";} if ($var3[$i] == "Wind SW wind") {echo " <img src='./images/wind/WindSW.png' alt='Wind SW wind' title='Wind SW wind'/><BR>";} if ($var3[$i] == "Wind W wind") {echo " <img src='./images/wind/WindW.png' alt='Wind W wind' title='Wind W wind'/><BR>";} if ($var3[$i] == "Wind NW wind") {echo " <img src='./images/wind/WindNW.png' alt='Wind NW wind' title='Wind NW wind'/><BR>";} if ($var3[$i] == "Strong N wind") {echo " <img src='./images/wind/WindN.png' alt='Strong N wind' title='Strong N wind'/><BR>";} if ($var3[$i] == "Strong NE wind") {echo " <img src='./images/wind/WindNE.png' alt='Strong NE wind' title='Strong NE wind'/><BR>";} if ($var3[$i] == "Strong E wind") {echo " <img src='./images/wind/WindE.png' alt='Strong E wind' title='Strong E wind'/><BR>";} if ($var3[$i] == "Strong SE wind") {echo " <img src='./images/wind/WindSE.png' alt='Strong SE wind' title='Strong SE wind'/><BR>";} if ($var3[$i] == "Strong S wind") {echo " <img src='./images/wind/WindS.png ' alt='Strong S wind' title='Strong S wind'/><BR>";} if ($var3[$i] == "Strong SW wind") {echo " <img src='./images/wind/WindSW.png' alt='Strong SW wind' title='Strong SW wind'/><BR>";} if ($var3[$i] == "Strong W wind") {echo " <img src='./images/wind/WindW.png' alt='Strong W wind' title='Strong W wind'/><BR>";} if ($var3[$i] == "Strong NW wind") {echo " <img src='./images/wind/WindNW.png' alt='Strong NW wind' title='Strong NW wind'/><BR>";} if ($var3[$i] == "Variable wind") {echo " <img src='./images/wind/Variablewind.gif' alt='Variable wind' title='Variable wind'/><BR>";} echo '</td>'; echo '</tr>'; echo '</table>'; echo '</td>'; }//fin if $var3 } echo '</tr>'; echo '<tr>'; echo '<th colspan="7">'; echo 'www.tiempo.com'; echo '</th>'; echo '</table>'; } ?> </body> </html>
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
</body> </html>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 </body> </html>

preferences:
218.71 ms | 401 KiB | 312 Q