Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>i tried this and it works:</p> <pre><code>&lt;? echo getWeatherForecast(''); function getWeatherForecast($atts) { $xml = simplexml_load_file('http://www.google.com/ig/api?weather=barcelona'); $information = $xml-&gt;xpath("/xml_api_reply/weather/forecast_information"); $current = $xml-&gt;xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml-&gt;xpath("/xml_api_reply/weather/forecast_conditions"); foreach ($forecast_list as $forecast) { ?&gt; &lt;div&gt; &lt;img src="&lt;?php echo 'http://www.google.com' . $forecast-&gt;icon['data']?&gt;" alt="weather"?&gt; &lt;div&gt;&lt;?php echo $forecast-&gt;day_of_week['data']; ?&gt;&lt;/div&gt; &lt;span&gt; &lt;?php echo $forecast-&gt;low['data'] ?&gt;&amp;deg; F – &lt;?php echo $forecast-&gt;high['data'] ?&gt;&amp;deg; F, &lt;?php echo $forecast-&gt;condition['data'] ?&gt; &lt;/span&gt; &lt;/div&gt; &lt;? } return '&lt;h2&gt;The weather today ' . $information[0]-&gt;city['data'] . '&lt;/h2&gt;'; /* etc. etc. */ } ?&gt; </code></pre> <p>but this is not right way to do that. Use one variable to accumulate html, and then return all the html. like this:</p> <pre><code>&lt;? echo getWeatherForecast(''); function getWeatherForecast($atts) { $xml = simplexml_load_file('http://www.google.com/ig/api?weather=barcelona'); $information = $xml-&gt;xpath("/xml_api_reply/weather/forecast_information"); $current = $xml-&gt;xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml-&gt;xpath("/xml_api_reply/weather/forecast_conditions"); $html = ''; foreach ($forecast_list as $forecast) { $html .= '&lt;div&gt;'; $html .= '&lt;img src="http://www.google.com'.$forecast-&gt;icon['data'].'" alt="weather"/&gt;'; $html .= '&lt;div&gt;'.$forecast-&gt;day_of_week['data'].'&lt;/div&gt;'; $html .= '&lt;span&gt;'; $html .= $forecast-&gt;low['data'].'&amp;deg; F – '.$forecast-&gt;high['data'].'&amp;deg; F,'.$forecast-&gt;condition['data']; $html .= '&lt;/span&gt;'; $html .= '&lt;/div&gt;'; } $html .= '&lt;h2&gt;The weather today ' . $information[0]-&gt;city['data'] . '&lt;/h2&gt;' return $html; /* etc. etc. */ } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload