Jump to content

fez

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

fez's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ooooh. I have just tried this code instead: $postcode = $geodata['town_city']; $requestAddress = "http://www.google.com/ig/api?weather=,,," . $postcode; $xml_str = file_get_contents($requestAddress,0); $xml = new SimplexmlElement($xml_str); And it works! (note the data being retrieved is now the town/city). Although this is great, it is not as accurate as the postcode/zipcode. I suspect this may be because of the space in the postcode? Is there a way to remove the space before declaring? Thanks
  2. Hi, I did post a question earlier but have now perhaps narrowed the problem and am still having trouble! I'm still learning PHP by working on a personal project. I'm having an issue accessing an xml file. If I use the following code I get a 'String could not be parsed as XML' error yet if I remove the $postcode variable when defining the $requestaddress variable and extend the url manually it works! $postcode = $geodata['postcode']; $requestAddress = "http://www.google.com/ig/api?weather=,,," . $postcode; $xml_str = file_get_contents($requestAddress,0); $xml = new SimplexmlElement($xml_str); Any suggestions greatly appreciated.
  3. Thanks. I tried what you said and it now throws this error: Warning: file_get_contents(http://www.google.com/ig/api?weather=,,,Bristol,Avon): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in - on line 64 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in -:65 Stack trace: #0 -(65): SimpleXMLElement->__construct('') #1 -(89): getWeather('http://www.goog...') #2 {main} thrown in - on line 65 ( line 64 is this one: $xml_str = file_get_contents($geourl,0); ) This is taking me way longer than I though it would
  4. How would I successfully do this? Like I said, I'm new here! I really do appreciate the help.
  5. Hmmm, yes I think you're right. When I use this code it works fine: $geourl = "http://www.google.com/ig/api?weather=,,,bristol,avon"; Yet, when I attempt to use the variables like before: $geourl = "http://www.google.com/ig/api?weather=,,," . $city . "," . $county; It doesn't work! What is different? Any ideas? Thanks again.
  6. Thanks, Thorpe. It actully does appear to be the line below that is causing the error ( $xml = new SimplexmlElement($xml_str); ) Here's the full code. <?php $city = "<script language='javascript'>document.write(geoip_city());</script>"; $county = "<script language='javascript'>document.write(geoip_region_name());</script>"; $geourl = "http://www.google.com/ig/api?weather=,,," . $city . "," . $county; function getWeather() { $xml_str = file_get_contents($geourl,0); $xml = new SimplexmlElement($xml_str); $count = 0; echo '<div id="weather">'; foreach($xml->weather as $item) { foreach($item->current_conditions as $new) { echo $new->condition['data']; echo '<br/>'; echo $new->temp_c['data']; echo '°C'; echo '<br/>'; echo $new->wind_condition['data']; } } echo '</div>'; } getWeather(); ?>
  7. Hi, I'm still pretty new to PHP and am currently working on a personal project to help learn. I am trying to detect a user's location, store their city and region and then build a URL containing these for later use. <?php $city = "<script language='javascript'>document.write(geoip_city());</script>"; $county = "<script language='javascript'>document.write(geoip_region_name());</script>"; $geourl = "http://www.google.com/ig/api?weather=,,," . $city . "," . $county; ?> If I echo $geourl then it displays just fine but when I attempt to use it, it throws an error 'String could not be parsed as XML' . $xml_str = file_get_contents($geourl,0); Any help appreciated, I just can't get my head around it! Fez
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.