src/Alg/Validation/LanguageValidator.php
public function getLanguage( $language )
	{
		$pattern		= '/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i';
		if( !$language )
			return $this->default;
		$accepted	= preg_split( '/,\s*/', $language );
		$curr_lang	= $this->default;
		$curr_qual	= 0;
		foreach( $accepted as $accept)
		{
			if( !preg_match ( $pattern, $accept, $matches) )
				continue;
			$lang_code = explode ( '-', $matches[1] );
			$lang_quality =  isset( $matches[2] ) ? (float)$matches[2] : 1.0;
			while (count ($lang_code))
			{
				if( in_array( strtolower( join( '-', $lang_code ) ), $this->allowed ) )
				{
					if( $lang_quality > $curr_qual )
					{
						$curr_lang	= strtolower( join( '-', $lang_code ) );
						$curr_qual	= $lang_quality;
						break;
					}
				}
				array_pop ($lang_code);
			}
		}
		return $curr_lang;
	}
public function getLanguage( $language )
	{
		$pattern		= '/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i';
		if( !$language )
			return $this->default;
		$accepted	= preg_split( '/,\s*/', $language );
		$curr_lang	= $this->default;
		$curr_qual	= 0;
		foreach( $accepted as $accept)
		{
			if( !preg_match ( $pattern, $accept, $matches) )
				continue;
			$lang_code = explode ( '-', $matches[1] );
			$lang_quality =  isset( $matches[2] ) ? (float)$matches[2] : 1.0;
			while (count ($lang_code))
			{
				if( in_array( strtolower( join( '-', $lang_code ) ), $this->allowed ) )
				{
					if( $lang_quality > $curr_qual )
					{
						$curr_lang	= strtolower( join( '-', $lang_code ) );
						$curr_qual	= $lang_quality;
						break;
					}
				}
				array_pop ($lang_code);
			}
		}
		return $curr_lang;
	}
public function getLanguage ( $ language ) { $ pattern = '/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i' ; if ( ! $ language ) return $ this -> default ; $ accepted = preg_split ( '/,\s*/' , $ language ) ; $ curr_lang = $ this -> default ; $ curr_qual = 0 ; foreach ( $ accepted as $ accept ) { if ( ! preg_match ( $ pattern , $ accept , $ matches ) ) continue ; $ lang_code = explode ( '-' , $ matches [ 1 ] ) ; $ lang_quality = isset ( $ matches [ 2 ] ) ? ( float ) $ matches [ 2 ] : 1.0 ; while ( count ( $ lang_code ) ) { if ( in_array ( strtolower ( join ( '-' , $ lang_code ) ) , $ this -> allowed ) ) { if ( $ lang_quality > $ curr_qual ) { $ curr_lang = strtolower ( join ( '-' , $ lang_code ) ) ; $ curr_qual = $ lang_quality ; break ; } } array_pop ( $ lang_code ) ; } } return $ curr_lang ; }
Returns prefered allowed and accepted Language.
@access		public
@param		string	$language		Language to prove
@return		string
Returns prefered allowed and accepted Language .