PHP code example of dartui / browser-language
1. Go to this page and download the library: Download dartui/browser-language library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dartui / browser-language example snippets
use Dartui\BrowserLanguage\BrowserLanguage;
/**
* Constructor tries to get Accept-Language value from $_SERVER superglobal.
*/
$browserLanguage = new BrowserLanguage();
/**
* Additionally you can pass Accept-Language header value
* or hardcoded value by yourself.
*/
$browserLanguage = new BrowserLanguage('en-US,en;q=0.5,pl;q=0.3');
/**
* Get the list of all supported languages sorted by factor.
* Example: [en-US, en, pl]
*/
$allLanguages = $browserLanguage->all();
/**
* Get the best match for user browser language.
* Example: en-US
*/
$language = $browserLanguage->best();