supportpal / accept-language-parser
ext-intl's locale_accept_from_http 函数的替代方案。
v0.2.1
2022-05-27 10:45 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-08-28 14:33:18 UTC
README
这是一个 PHP 版本的 npm:accept-language-parser,也是 ext-intl locale_accept_from_http 函数的等价物。
安装
composer require supportpal/accept-language-parser
用法
解析
解析 ACCEPT_LANGUAGE 标头并返回所有解析后的区域设置。
$parser = new \SupportPal\AcceptLanguageParser\Parser($_SERVER['http_accept_language']); foreach ($parser->parse() as $component) { echo $component->code(); }
选择
解析 ACCEPT_LANGUAGE 标头并只返回与请求匹配的区域设置。
$parser = new \SupportPal\AcceptLanguageParser\Parser('en-GB;q=0.8'); foreach ($parser->pick(array('en')) as $component) { echo $component->code(); }
许可证
本软件包采用 MIT 许可证 许可。