IntlChar::charName()函數是PHP中的一個內置函數,用於檢索Unicode字符的名稱。
用法:
string IntlChar::charName( $codepoint [, $nameChoice = IntlChar::UNICODE_CHAR_NAME] )
參數:該函數接受上述和以下描述的兩個參數:
- $codepoint:此參數是字符或整數值,編碼為UTF-8字符串。
- $nameChoice:$nameChoice參數滿足以下任何恒定條件之一:
- IntlChar::UNICODE_CHAR_NAME(默認)
- IntlChar::CHAR_NAME_ALIAS
- IntlChar::CHAR_NAME_CHOICE_COUNT
- IntlChar::UNICODE_10_CHAR_NAME
- IntlChar::EXTENDED_CHAR_NAME
注意:產生的字符名稱是Unicode版本1.0的現代名稱,並且該名稱包含“invariant”字符A-Z,0-9,“”和“-”,並取決於其$nameChoice參數。
返回值:此函數返回輸入數據的相應名稱。如果沒有字符名稱,則返回空字符串。
以下示例程序旨在說明PHP中的IntlChar::charName()函數。程序1:
<?php
// PHP code to illustrate
// IntlChar::charName ()function
// Input astrick symbol of codepoint value
// with constraint UNICODE_CHAR_NAME
var_dump(IntlChar::charName("*"));
var_dump(IntlChar::charName("*", IntlChar::UNICODE_CHAR_NAME));
// Input start bracket symbol of codepoint value
// with constraint UNICODE_10_CHAR_NAME
var_dump(IntlChar::charName("("));
var_dump(IntlChar::charName("(", IntlChar::UNICODE_10_CHAR_NAME));
// Input ampersand symbol of codepoint value
// with constraint EXTENDED_CHAR_NAME
var_dump(IntlChar::charName("&"));
var_dump(IntlChar::charName("&", IntlChar::EXTENDED_CHAR_NAME));
// Input ^ symbol of codepoint value
// with constraint CHAR_NAME_ALIAS
var_dump(IntlChar::charName("^"));
var_dump(IntlChar::charName("^", IntlChar::CHAR_NAME_ALIAS ));
// Input tile symbol of codepoint value
//and with constraint CHAR_NAME_CHOICE_COUNT
var_dump(IntlChar::charName("`"));
var_dump(IntlChar::charName("`", IntlChar::CHAR_NAME_CHOICE_COUNT));
// Input space of codepoint value
var_dump(IntlChar::charName(" "));
// Input space in codepoint value with
// UNICODE_CHAR_NAME condition
var_dump(IntlChar::charName(" ", IntlChar::UNICODE_CHAR_NAME));
// Input Alphabet both Capital and Small character
// condition EXTENDED_CHAR_NAME
// and UNICODE_10_CHAR_NAME
var_dump(IntlChar::charName("R"));
var_dump(IntlChar::charName("r"));
var_dump(IntlChar::charName("R", IntlChar::EXTENDED_CHAR_NAME));
// Input int codepoint value
var_dump(IntlChar::charName("10"));
var_dump(IntlChar::charName("7"));
// Input Null codepoint value
var_dump(IntlChar::charName("\u{0000}"));
?>
輸出:
string(8) "ASTERISK" string(8) "ASTERISK" string(16) "LEFT PARENTHESIS" string(0) "" string(9) "AMPERSAND" string(9) "AMPERSAND" string(17) "CIRCUMFLEX ACCENT" string(0) "" string(12) "GRAVE ACCENT" NULL string(5) "SPACE" string(5) "SPACE" string(22) "LATIN CAPITAL LETTER R" string(20) "LATIN SMALL LETTER R" string(22) "LATIN CAPITAL LETTER R" NULL string(11) "DIGIT SEVEN" string(0) ""
程序2:
<?php
// PHP code to illustrate
// IntlChar::charName() function
// Declare an array $arr
$arr = array("G", ".", "8", "/", "000", "\t");
// Loop run for every array element
foreach ($arr as $val){
// Check each element as code point data
var_dump(IntlChar::charName($val));
}
?>
輸出:
string(22) "LATIN CAPITAL LETTER G" string(9) "FULL STOP" string(11) "DIGIT EIGHT" string(7) "SOLIDUS" NULL string(0) ""
相關文章:
參考: http://php.net/manual/en/intlchar.charname.php
相關用法
- d3.js d3.lab()用法及代碼示例
- PHP exp()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP abs()用法及代碼示例
- PHP cos( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP next()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- d3.js d3.sum()用法及代碼示例
- PHP pi( )用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | IntlChar::charName() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。