src/Net/HTTP/Sniffer/Language.php
public static function getLanguageFromString( $string, $allowed, $default = false )
	{
		if( !$default)
			$default = $allowed[0];
		if( !$string )
			return $default;
		$accepted	= preg_split( '/,\s*/', $string );
		$currentLanguage	= $default;
		$currentQuality		= 0;
		foreach( $accepted as $accept )
		{
			if( !preg_match( self::$pattern, $accept, $matches ) )
				continue;
			$languageCode = explode ( '-', $matches[1] );
			$languageQuality =  isset( $matches[2] ) ? (float) $matches[2] : 1.0;
			while( count( $languageCode ) )
			{
				if( in_array( strtolower( join( '-', $languageCode ) ), $allowed ) )
				{
					if( $languageQuality > $currentQuality )
					{
						$currentLanguage	= strtolower( join( '-', $languageCode ) );
						$currentQuality		= $languageQuality;
						break;
					}
				}
				array_pop( $languageCode );
			}
		}
		return $currentLanguage;
	}
public static function getLanguageFromString( $string, $allowed, $default = false )
	{
		if( !$default)
			$default = $allowed[0];
		if( !$string )
			return $default;
		$accepted	= preg_split( '/,\s*/', $string );
		$currentLanguage	= $default;
		$currentQuality		= 0;
		foreach( $accepted as $accept )
		{
			if( !preg_match( self::$pattern, $accept, $matches ) )
				continue;
			$languageCode = explode ( '-', $matches[1] );
			$languageQuality =  isset( $matches[2] ) ? (float) $matches[2] : 1.0;
			while( count( $languageCode ) )
			{
				if( in_array( strtolower( join( '-', $languageCode ) ), $allowed ) )
				{
					if( $languageQuality > $currentQuality )
					{
						$currentLanguage	= strtolower( join( '-', $languageCode ) );
						$currentQuality		= $languageQuality;
						break;
					}
				}
				array_pop( $languageCode );
			}
		}
		return $currentLanguage;
	}
public static function getLanguageFromString ( $ string , $ allowed , $ default = false ) { if ( ! $ default ) $ default = $ allowed [ 0 ] ; if ( ! $ string ) return $ default ; $ accepted = preg_split ( '/,\s*/' , $ string ) ; $ currentLanguage = $ default ; $ currentQuality = 0 ; foreach ( $ accepted as $ accept ) { if ( ! preg_match ( self :: $ pattern , $ accept , $ matches ) ) continue ; $ languageCode = explode ( '-' , $ matches [ 1 ] ) ; $ languageQuality = isset ( $ matches [ 2 ] ) ? ( float ) $ matches [ 2 ] : 1.0 ; while ( count ( $ languageCode ) ) { if ( in_array ( strtolower ( join ( '-' , $ languageCode ) ) , $ allowed ) ) { if ( $ languageQuality > $ currentQuality ) { $ currentLanguage = strtolower ( join ( '-' , $ languageCode ) ) ; $ currentQuality = $ languageQuality ; break ; } } array_pop ( $ languageCode ) ; } } return $ currentLanguage ; }
Returns prefered allowed and accepted Language from String.
@access		public
@static
@param		array	$allowed		Array of Languages supported and allowed by the Application
@param		string	$default		Default Languages supported and allowed by the Application
@return		string
Returns prefered allowed and accepted Language from String .