Jump to content

variable in an address


paulmo

Recommended Posts

that looks fine. I was thinking that was more along the lines of what DD was suggesting with trim. One option is echo the text using a style to give the output a background. That way you can check to see if there is extra space or something. It might also be worth echo'ing the value from geolocate before and after being assigned to $city and $st, see if there's any difference. i.e.

echo geolocate->city;echo geolocate->state;$city = geolocate->city;$state = geolocate->state;echo $city;echo $state;

Link to comment
Share on other sites

Playing around with this, getting failed to open stream 400 bad request, on dynamic variable, which is good:

Uncaught exception 'Exception' with message 'String could not be parsed as XML'...file_get_contents(http://www.google.com/ig/api?weather=Waterville, ME) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in
Waterville, ME is from dynamic variable now, yet the weather icons are not rendering. I'm confused because this city, (space) state abbrev. is actually like the script docs.
$city = $geoplugin->city;$st = $geoplugin->region;$requestAddress = "http://www.google.com/ig/api?weather=$city, $st";$xml_str = file_get_contents($requestAddress,0);function getWeather() {$xml = new SimplexmlElement($xml_str);var_dump($xml);

etc...

Link to comment
Share on other sites

try removing the space between the comma and $st.Maybe slap this down on $requestAddress as well.http://php.net/manual/en/function.urlencode.phpedit: was there any difference between the echo of geolocate before and after the variable assignments?try trimming everything too. what does the URL look like before you put it in file_get_contents? I would always be echo'ing that out.

Link to comment
Share on other sites

So I got a copy of geoplugin.class.php . Have you been calling $geoplugin->locate() ? I ask because the result you reported in Post #21 is what you get if you don't call that method before accessing properties of the geoPlugin object.The code below works for me, giving a complete report for my browser's area. (It's going to snow.) I haven't bothered to parse the XML, just echoed it with a header so my browser would know how to read it:

<?php   require_once('geoplugin.class.php');   $geoplugin = new geoPlugin();   $geoplugin->locate();   $city = $geoplugin->city;   $state = $geoplugin->region;   $requestAddress = "http://www.google.com/ig/api?weather=$city,$state";   $xml_str = file_get_contents($requestAddress);   header("Content-type: text/xml");   echo $xml_str;?>

If this code doesn't work on your system, you might try passing the complete URL to simplexml_load_file() and just forget about file_get_contents.Oh, yes. If you're not passing an IP to your object, you might try echoing $_SERVER['REMOTE_ADDR'] , since that is the default IP the object uses. If the address there isn't real (like 10.0.0.1 or something local), this thing won't work. Like if you're running your browser and server on your desktop, so no real IP is set . . .

Link to comment
Share on other sites

wasn't the OP echoing the value of $city and $state before using them? I could've sworn that had been looked into first...(as he said he had been using them already in the page, script, etc)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...