Collator::getAttribute()

获取 Collator 对象的当前属性值

首字母:C

函数名:Collator::getAttribute()

函数描述:Collator::getAttribute() 函数用于获取 Collator 对象的当前属性值。

用法:

public Collator::getAttribute ( int $attr ) : int

参数:

  • $attr:属性的常量值。可选常量包括 Collator::FRENCH_COLLATION、Collator::ALTERNATE_HANDLING、Collator::CASE_FIRST、Collator::CASE_LEVEL、Collator::NORMALIZATION_MODE、Collator::STRENGTH 和 Collator::NUMERIC_COLLATION。

返回值:

  • 返回当前属性的值,如果属性无效或不可用,则返回 false。

示例:

$collator = new Collator('en_US');
// 获取当前排序规则是否基于法语
$frenchCollation = $collator->getAttribute(Collator::FRENCH_COLLATION);
if ($frenchCollation === Collator::ON) {
 echo "当前排序规则基于法语\n";
} else {
 echo "当前排序规则不基于法语\n";
}
// 获取当前排序规则对大小写的处理方式
$alternateHandling = $collator->getAttribute(Collator::ALTERNATE_HANDLING);
if ($alternateHandling === Collator::NON_IGNORABLE) {
 echo "当前排序规则对大小写敏感\n";
} else {
 echo "当前排序规则对大小写不敏感\n";
}

以上示例中,我们创建了一个英语环境的 Collator 对象。然后,我们通过 getAttribute() 函数获取了当前排序规则是否基于法语和当前排序规则对大小写的处理方式。根据返回值,我们可以相应地输出结果。

同首字母函数