Geoffrey B. Veteran Posted February 2, 2011 Veteran Share Posted February 2, 2011 I am attempting to add weather information to a page using the google weather API (of which documentation is scarce) This is what I have so far. HEAD <?php $xml = simplexml_load_file('http://www.google.com/ig/api?weather=43055'); $information = $xml->xpath("/xml_api_reply/weather/forecast_information"); $current = $xml->xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); ?> BODY <h2>Today's weather</h2> <div class="weather"> <img src="<?php= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"/> <span class="condition"> <?php= $current[0]->temp_f['data'] ?>° F, <?php= $current[0]->condition['data'] ?> </span> </div> However when I run it the XML does produce Data yet the page displays this weather temp_f['data'] ?>? F, condition['data'] ?> The word "weather" is actually an image that looks just like the text if i had not selected it to copy i would not have known it were an image. Am i doing something wrong? Link to comment Share on other sites More sharing options...
0 Calculator Posted February 2, 2011 Share Posted February 2, 2011 I don't think <?php=$a ?> is a valid PHP tag. You can use <?php echo $a; ?> or <?=$a ?> (if short_tags is enabled) but there's no such thing as <?php=$a ?>. (I like the idea though. :p) Try replacing those faulty tags with valid alternatives and see if it works then. Link to comment Share on other sites More sharing options...
0 psp83 Posted February 2, 2011 Share Posted February 2, 2011 Calculator is correct. Here's the working code: <?php function dump($var) { print('<pre>'); print_r($var); print('</pre>'); } $xml = simplexml_load_file('http://www.google.com/ig/api?weather=43055'); $information = $xml->xpath("/xml_api_reply/weather/forecast_information"); $current = $xml->xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); ?> <h2>Today's weather</h2> <div class="weather"> <img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"/> <span class="condition"> <?php echo $current[0]->temp_f['data'] ?>° F, <?php echo $current[0]->condition['data'] ?> </span> </div> <?php dump($information); dump($current); dump($forecast_list); ?> Here's a link to it working : http://psp83.co.uk/scripts/weather.php Link to comment Share on other sites More sharing options...
0 Geoffrey B. Veteran Posted February 2, 2011 Author Veteran Share Posted February 2, 2011 I cannot believe i did that lol. :p thank you Link to comment Share on other sites More sharing options...
Question
Geoffrey B. Veteran
I am attempting to add weather information to a page using the google weather API (of which documentation is scarce)
This is what I have so far.
HEAD
<?php $xml = simplexml_load_file('http://www.google.com/ig/api?weather=43055'); $information = $xml->xpath("/xml_api_reply/weather/forecast_information"); $current = $xml->xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); ?>BODY
<h2>Today's weather</h2> <div class="weather"> <img src="<?php= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"/> <span class="condition"> <?php= $current[0]->temp_f['data'] ?>° F, <?php= $current[0]->condition['data'] ?> </span> </div>However when I run it the XML does produce Data yet the page displays this
The word "weather" is actually an image that looks just like the text if i had not selected it to copy i would not have known it were an image.
Am i doing something wrong?
Link to comment
Share on other sites
3 answers to this question
Recommended Posts