From: Philip Tzou Date: Fri, 22 May 2009 17:40:00 +0000 (+0000) Subject: Follow up on r49157. Fixed the header parsing code to conform to RFC 2616 section... X-Git-Tag: 1.31.0-rc.0~41690 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=50f29c7e115851e558d822466d4243013edf1987;p=lhc%2Fweb%2Fwiklou.git Follow up on r49157. Fixed the header parsing code to conform to RFC 2616 section 14.4. --- diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index df5409b3e3..746adb737d 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -184,8 +184,17 @@ class LanguageConverter { // preference is loaded if( array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) { $acceptLanguage = str_replace( '_', '-', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"])); - $languages = preg_split('/[,;]/', $acceptLanguage); + + // take the part of the string up to the first semicolon + if($semiPos = strpos( $acceptLanguage, ';' ) !== false ) + $acceptLanguage = substr( $acceptLanguage, 0, $semiPos ); + + // explode by comma + $languages = explode(',', $acceptLanguage); + foreach( $languages as $language ) { + // strip whitespace + $language = trim( $language ); if( in_array( $language, $this->mVariants ) ) { return $language; break;