A PHP port of npm:accept-language-parser and an equivalent to the ext-intl locale_accept_from_http function.
composer require supportpal/accept-language-parser
Parses an ACCEPT_LANGUAGE header and returns all parsed locales.
$parser = new \SupportPal\AcceptLanguageParser\Parser($_SERVER['http_accept_language']);
foreach ($parser->parse() as $component) {
echo $component->code();
}
Parses an ACCEPT_LANGUAGE header and returns only locales which match those requested.
$parser = new \SupportPal\AcceptLanguageParser\Parser('en-GB;q=0.8');
foreach ($parser->pick(array('en')) as $component) {
echo $component->code();
}
This package is licensed under the MIT License.