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

  • Home
  • SEARCH
  • 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 7916871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:58:00+00:00 2026-06-03T14:58:00+00:00

I am using the Facebook Graph API to get the users locale information (updated

  • 0

I am using the Facebook Graph API to get the users locale information (updated code):

[more code]
<div id="scoreboard-overview">
    <ul>';
    $num_rows = mysql_num_rows($resulttt);
    $i = 0;
        while($row = mysql_fetch_array($resulttt)) {
            $i = $i + 1;
            $fb_data = json_decode(file_get_contents('http://graph.facebook.com/'. $row['fbID']));
            $fb_locale_str = $fb_data->locale;
            $fb_name_str = $fb_data->first_name;
            $fb_country_str = strtolower(substr($fb_locale_str, -2));
            $flag_uri = '/flags/unknown.gif'; //display a general flag if unknown.
            if (!empty($fb_country_str) && in_array($fb_country_str, $valid_flags) )
                $flag_uri = '/flags/' . $fb_country_str . '.gif';

echo '<li>
        <div class="container">
            <div class="black">
                <img src="https://graph.facebook.com/'. $row['fbID'] .'/picture" alt="" />
            </div>
            <div class="grey">
                '.$i.' '.$fb_name_str.'';
            printf ('<div class="test"><img src="%s" /></div>', $flag_uri); 
    echo '      </div>
            <div class="holder">
                <div class="blue">
                    <p>0<br />'. $row['Time'] .'</p>
                </div>
                <div class="red">
                    <img src="http://ep2.nl/images/star.gif" alt="" />
                </div>
                <div class="yellow">
                    <p>'. $row['Score'] .'</p>
                </div>
            </div> 
        </div>
    </li>';
        }
echo '</ul>
</div>
    [more code]

$row['fbID'] is the users and/or friends Facebook ID (used in a array)

Well this gives a result like: en_US where en is the users language and US is the users country. The country is where I am after.

I have a couple of flag images that look like this: us.png. These flags are named using the ISO3166-1 alpha-2 country codes where appropriate. So I want to trim this en_US to us and put .png behind it so I can show the flag image. But how to do this?

Also a general flag if the locale returns nothing like unknown.png would be nice.

Many thanks,

Maurice

  • 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-06-03T14:58:03+00:00Added an answer on June 3, 2026 at 2:58 pm

    Not too hard to do.

    Try this:

    $valid_flags = array ('us', 'ca', 'mx', '...') //You'll need to populate this one
    
    $fb_data = json_decode(file_get_contents('http://graph.facebook.com/'. $row['fbID']);
    $fb_locale_str = $fb_data->location;
    $fb_country_str = strtolower(substr($fb_locale_str, -2));
    $flag_uri = '/flags/unknown.png'; //display a general flag if unknown.
    if (!empty($fb_country_str) && in_array($fb_country_str, $valid_flags) )
        $flag_uri = '/flags/' . $fb_country_str . '.png';
    printf ('<div class="grey"><img src="%s" /></div>', $flag_uri);
    

    As a note, you shouldn’t be calling file_get_contents inside of an echo statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve information through Facebook graph api, using the below code
I'm using a foreach loop to get images from the graph API in facebook.
I am trying to get user album by using GRAPH API with function facebook.request(contact.getFacebook_id()+/albums)
i'm using facebook graph api to get the current user friend list. i have
I am using facebook graph api and I am able to get the email
I'm using C# in MonoDevelop with the Graph API to interact with users facebook
Is it possible to send direct message using the facebook graph api? I’ve read
I'm using Koala for Facebook Graph API calls and am using a block for
I created an APP on Facebook and using graph API explorer, I selected my
I have a Facebook desktop application and am using the Graph API . I

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.