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 8986439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:33:00+00:00 2026-06-15T21:33:00+00:00

Possible Duplicate: HTTP_ACCEPT_LANGUAGE i try to code a language option tool. therefor i use

  • 0

Possible Duplicate:
HTTP_ACCEPT_LANGUAGE

i try to code a language option tool. therefor i use

$default_language = (strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));

if (eregi('af', $default_language)) {do something}

now i would like to order the string when i will echo:

$_SERVER["HTTP_ACCEPT_LANGUAGE"]

for example an user has specified a number of languages.

example for chrome with different languages:

 nl,en-gb;q=0.8,en;q=0.6,fr;q=0.4,fr-ca;q=0.2

so how can i read out the string to bring it in a certain order where i can see that nl is the first language that is prefered.

the code should be something like:

if ('nl'== array[0]) {do something}

so if there is someone who could help me out i really would appreciate.

thanks alot.

  • 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-15T21:33:02+00:00Added an answer on June 15, 2026 at 9:33 pm

    From HTTP/1.1 Header Field Definitions:

    Each language-range MAY be given an associated quality value which represents an estimate of the user’s preference for the languages specified by that range. The quality value defaults to “q=1”.

    You have to loop over languages and select one with highest quality (preferrence); like this:

    $preferred = "en"; // default
    if(isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
    {
        $max   = 0.0;
        $langs = explode(",", $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
        foreach($langs as $lang)
        {
            $lang = explode(';', $lang);
            $q    = (isset($lang[1])) ? ((float) $lang[1]) : 1.0;
            if ($q > $max)
            {
                $max = $q;
                $preferred = $lang[0];
            }
        }
        $preferred = trim($preferred);
    }
    // now $preferred is user's preferred language
    

    If Accept-Language header is not sent, all languages are equally acceptable.

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

Sidebar

Related Questions

Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Ruby/Ruby on Rails ampersand colon shortcut As a habit I try and
Possible Duplicate: PHP - opendir on another server Something like this: opendir(http://super.cdn.com/running_order_image/sale/587/) The opendir
Possible Duplicate: get current latitude and longitude from gps enabled device I use the
Possible Duplicate: return a specific http status code with php How can I programmatically
Possible Duplicate: HTTP_HOST vs. SERVER_NAME What is the difference between $_SERVER['HTTP_HOST'] and $_SERVER['SERVER_NAME'] ??
Possible Duplicate: Testing use of NSURLConnection with HTTP response error statuses This is bizarre;
Possible Duplicate: PHP + curl, HTTP POST sample code? POST data to URL php
Possible Duplicate: What good is JSLint if jQuery fails the validation http://code.jquery.com/jquery-1.4.4.js Go to
Possible Duplicate: difference between http.context.user and thread.currentprincipal and when to use them? What's the

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.