Skip to content

Instantly share code, notes, and snippets.

View joke2k's full-sized avatar
🏠
Working from home

Daniele Faraglia joke2k

🏠
Working from home
View GitHub Profile
@joke2k
joke2k / get-browser-language.php
Last active March 22, 2024 05:25 — forked from LucaRosaldi/get-browser-language-code.php
PHP: Detect Browser Language
<?php
/**
* Get browser language, given an array of avalaible languages.
*
* @param [array] $availableLanguages Avalaible languages for the site
* @param [string] $default Default language for the site
* @return [string] Language code/prefix
*/
function get_browser_language( $available = [], $default = 'en' ) {
if ( isset( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] ) ) {