help with php and xml for yahoo service -
I am working on a PHP code for my social network, which I'm planning to do is either user signup or Profiles are on update. I take zip codes wherever they use Yahoo and I keep these values from there to see latitude and logatigraphy, there the user's MySQL table is used. But those users' Located within miles will be used to find users. / P>
& lt ;? My code is so far to get this information before depositing in php function yahoo_geo ($ location) {$ q = 'http: // api. I .local.yahoo.com/MapService / V1 / geocode'; Q = '? APID = Rarlinhof and location = '. Rawerlencode ($ location); Echo $ q; Libxml_use_internal_errors (true); $ Xml = Simple XMLload_file ($ q); If (! Is_object ($ xml)) returned incorrectly; $ Ret ['exact'] = (string) $ xml- & gt; Results ['exact']; Foreign currency ($ xml-> result-> children () $ key = & gt; $ val) {if (strlen ($ val)) {$ ret [(string) $ key] = (string) $ val; } Return $ ret; } $ _REQUEST ['place'] = 32744; // my ZIP code $ a = yahoo_geo ($ _ request ['location']); // MySQL $ Latitude = $ a [Latitude] Set the data again for some variables; $ Longitude = $ a [longitude]; // MySQL code goes here // Output 'LETITUDE' echo for display $ Latitude '& lt; BR & gt; & Lt; BR & gt; '; 'Longitude' echo $ Longitude '& lt; BR & gt; & Lt; BR & gt; '; ? & Gt;
This works great if long and no latitude is found. This gives the browser an error.
Warning: simplexml_load_file (http: / /api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&location= some non zipcode) [function.simplexml-load-file]: Failed to open stream: HTTP request failed! HTTP / 1.1 400 Bad Request C: \ webserver \ htdocs \ test \ geolocation \ index.php on line 16
Note; I can make sure that the zipcode is only numeric but I will not, but instead let me search with other fields as yewoo, so if a user does not enter the zipcode, then I can call it city or state or even country In case of every user, there should be any type of longitude and latitude. Saved
A good way to show error or to avoid better than that is to find an ID and if there is an error then can I put a default value for that user?
It is not absolutely certain what your question is, but I think that you
xml = @simplexml_load_file ($ q);
Your function will return false as normal. You will have to check later (and add some quotes):
if (! $ A) { // something) and {$ latitude = $ a ['latitude']; $ Longitude = $ a ['longitude']; }
Comments
Post a Comment