I've been trying to figure this out all day. Searching for possible rewrites, ANYTHING, but to no avail. This script works just fine when the city is a one word city such as 'Seattle'. However, When it's something like 'Los Angeles' I get error signs. I know that this is being cause because the city is being called from the URL and comes up as 'Los%20Angeles'. Is there anyway within this code that I code convert a '%20' to a '+'? <?php $city = $_GET['city']; $request = 'http://local.yahooapis.com/MapsService/V1/mapImage?appid=<my_id>&image_height=103&image_width=194&city=' . $city . '&state=' . $abbr . '&zoom=4&radius=10&output=php'; $response = file_get_contents($request); if ($response === false) { die('sorry'); } $phpobj = unserialize($response); echo '<img src="'.$phpobj["Result"].'">'; ?> PHP:
Yes you can simply use like that : <?php $city = $_GET['city']; $city = str_replace("%20","+",$city ); or there be also inbuild function to use this for url encode and decode......
singh, I've tried that before and it didn't work. Still returns an error message. Azizny, I'm not sure I really understand how to use that. Within that code, am I suppose to substitute something there with '$city'?
Strange that it returns an error message. Can you post it here? Otherwise, you could try with preg_replace instead of str_replace: $city = $_GET['city']; $city = preg_replace('%20', '+', $city);
elias, when I tried that it showed the map but starred location was not in right place AND gave this message: Warning: preg_replace() [function.preg-replace]: No ending delimiter '%' found in /home/coyoloko/public_html/yahoo_api.php on line 4 tamilsoft, with that I just get this error: Warning: file_get_contents(http://local.yahooapis.com/MapsServ...4-&image_height=103&image_width=194&city=Palm Springs&state=CA&zoom=4&radius=10&output=php) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/coyoloko/public_html/yahoo_api.php on line 7 I really appreciate everyone's help. Hopefully I can get this figured out.