首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Locale::lookup

(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)

Locale::lookup -- locale_lookup — Searches the language tag list for the best match to the language

Description

Object oriented style

代码语言:javascript
复制
public static string Locale::lookup ( array $langtag , string $locale [, bool $canonicalize = false [, string $default ]] )

Procedural style

代码语言:javascript
复制
string locale_lookup ( array $langtag , string $locale [, bool $canonicalize = false [, string $default ]] )

Searches the items in langtag for the best match to the language range specified in locale according to RFC 4647's lookup algorithm.

Parameters

langtag

An array containing a list of language tags to compare to locale. Maximum 100 items allowed.

locale

The locale to use as the language range when matching.

canonicalize

If true, the arguments will be converted to canonical form before matching.

default

The locale to use if no match is found.

Return Values

The closest matching language tag or default value.

Examples

Example #1 locale_lookup() example

代码语言:javascript
复制
<?php
$arr?=?array(
????'de-DEVA',
????'de-DE-1996',
????'de',
????'de-De'
);
echo?locale_lookup($arr,?'de-DE-1996-x-prv1-prv2',?true,?'en_US');
?>

Example #2 OO example

代码语言:javascript
复制
<?php
$arr?=?array(
????'de-DEVA',
????'de-DE-1996',
????'de',
????'de-De'
);
echo?Locale::lookup($arr,?'de-DE-1996-x-prv1-prv2',?true,?'en_US');
?>

The above example will output:

代码语言:javascript
复制
de_de_1996

See Also

  • locale_filter_matches() - Checks if a language tag filter matches with locale

← Locale::getScript

Locale::parseLocale →

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com