文字

http_negotiate_language

(PECL pecl_http >= 0.1.0)

http_negotiate_languageNegotiate client's preferred language

说明

string http_negotiate_language ( array $supported [, array &$result ] )

This function negotiates the client's preferred language based on its Accept-Language HTTP header. The qualifier is recognized and languages without qualifier are rated highest. The qualifier will be decreased by 10% for partial matches (i.e. matching primary language).

参数

supported

array containing the supported languages as values

result

will be filled with an array containing the negotiation results

返回值

Returns the negotiated language or the default language (i.e. first array entry) if none match.

范例

Example #1 Using http_negotiate_language()

<?php
$langs 
= array(
        
'en-US' , // default
        
'fr' ,
        
'fr-FR' ,
        
'de' ,
        
'de-DE' ,
        
'de-AT' ,
        
'de-CH' ,
);

include 
'./langs/' http_negotiate_language ( $langs $result ) . '.php' ;

print_r ( $result );
?>

用户评论:

[#1] Mahn [2015-05-08 21:38:57]

This method can be found as http\Env::negotiateLanguage in the http pecl module version 2, see here: http://devel-m6w6.rhcloud.com/mdref/http/Env/negotiateLanguage

上一篇: 下一篇: