syonix / http-header-accept-language
A parser for the Accept-Language HTTP header following RFC 2616
Installs: 515
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/syonix/http-header-accept-language
Requires (Dev)
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2025-09-29 02:29:07 UTC
README
A parser for the Accept-Language HTTP header following RFC 2616
Usage
use Syonix\Http\Header\AcceptLanguage\AcceptLanguage; $parsed = AcceptLanguage::parse('da, en-gb;q=0.8, en;q=0.7'); // Returns Array ordered by quality (q) $parsed = AcceptLanguage::match('de-CH, de-DE;q=0.9, de;q=0.8', ['de-DE', 'de']); // Returns 'de-DE'
Notes
AcceptLanguage::match()
throws a RuntimeException, if none of the accepted languages matches and*
is not in theAccept-Languages
string.- If
*
is accepted and none of the other accepted languages match, the passed$default
parameter is passed - If
$default
is omitted, the first element of the$locale
array is returned. - Both
parse
andmatch
are case insensitive. parse
always returns the case of the input stringmatch
always returns the case of the provided locale array.- As per the RFC, the quality value defaults to
q=1
.