Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 290853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:02:08+00:00 2026-05-12T06:02:08+00:00

I am working on a PHP code for my social network, what I am

  • 0

I am working on a PHP code for my social network, what I am planning to do is on user signup or profile update
I will take there zipcode that they enter and use yahoo to lookup there lattitude and logitude from there zipcode
I will then save these value to there user mysql table, this will be used later on to find users located within X amount
of miles from them.

Here is my code so far to get this info before storing into DB

<?PHP
function yahoo_geo($location) {
    $q = 'http://api.local.yahoo.com/MapsService/V1/geocode';
    q .= '?appid=rlerdorf&location='.rawurlencode($location);
    echo $q;
    libxml_use_internal_errors(true);
    $xml = simplexml_load_file($q); 
    if(!is_object($xml)) return false;
    $ret['precision'] = (string)$xml->Result['precision'];
    foreach($xml->Result->children() as $key=>$val) {
        if(strlen($val)){
            $ret[(string)$key] =  (string)$val;
        } 
    return $ret;
}

$_REQUEST['location'] = 32744; // my zip code
$a = yahoo_geo($_REQUEST['location']);

// set retunred data to some variables for storage into MySQL
$latitude = $a[Latitude];
$longitude = $a[Longitude];

    // MySQL code will go here

// Output for demo
echo 'Lattitude' .$latitude. '<BR><BR>';
echo 'Longitude' .$longitude. '<BR><BR>';
?>

This works great except if a long. and lat. is not found it returns an error to the browser

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 in C:\webserver\htdocs\test\geolocation\index.php on line 16

Note; I could make sure that zipcode is numeric only but I would rather not as yahoo will let me search with other fields as well, so If a user does not enter a zipcode I will make it use a city or state or even country at the worse case so every user should have some sort of longitude and lat. saved

Is there a good way to avoid the error showing or even better is there a way to detect id there is an error and if an error occurs I could insert a default value for that user?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:02:09+00:00Added an answer on May 12, 2026 at 6:02 am

    Not exactly sure what your question is, but I think you’re looking for the error control operator @

    xml = @simplexml_load_file($q);
    

    Your function will then return false as normal.
    You need to check that later though (and add some quotes):

    if (!$a)
    {
        // Do something
    }
    else
    {
        $latitude = $a['Latitude'];
        $longitude = $a['Longitude'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 313k
  • Answers 313k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should create a sparse working copy that only contains… May 13, 2026 at 10:55 pm
  • Editorial Team
    Editorial Team added an answer OK i solved the problem, with the following delegate Method:… May 13, 2026 at 10:55 pm
  • Editorial Team
    Editorial Team added an answer (?=…) and (?!…) (lookaheads) asserts that the string after it… May 13, 2026 at 10:55 pm

Related Questions

I am working on a AJAX/jquery notification script. Currently it retunrs a whole fhtml
I am working on a PHP function that will recursively remove all sub-folders that
I am working on a website using a PHP script to display information formatted
I am working on a few PHP projects that use MVC frameworks, and while

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.