当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP IntlChar::totitle()用法及代码示例


IntlChar::totitle()函数是PHP中的内置函数,用于检查输入代码点是否为Unicode字符标题。

用法:

mixed IntlChar::totitle( $codepoint )

参数:该函数接受单个参数$codepoint,该参数是必需的。 $codepoint参数是一个字符或整数值,编码为UTF-8字符串。


返回值:返回代码点的simple_Titlecase_Mapping(如果有);否则代码本身。除非代码点作为UTF-8字符串传递,否则返回类型将为整数,在这种情况下将返回字符串。

以下示例程序旨在说明PHP中的IntlChar::totitle()函数:

程序1:

<?php 
// PHP function to illustrate the 
// use of IntlChar::totitle() 
    
// Input Capital letter  codepoint 
var_dump(IntlChar::totitle("G")); 
   
// Input Capital letter  codepoint 
var_dump(IntlChar::totitle("g")); 
   
// Input Capital letter  codepoint 
var_dump(IntlChar::totitle("a")); 
   
// Input int char an identifier 
// of codepoint value 
var_dump(IntlChar::totitle("\u{00A0}")); 
    
// Input symbolic space codepoint value  
var_dump(IntlChar::totitle(" ")); 
   
// Input symbolic codepoint value  
var_dump(IntlChar::totitle(" ^ ")); 
   
// Input int codepoint value  
var_dump(IntlChar::totitle("9")); 
   
// Input control character codepoint value  
var_dump(IntlChar::totitle("\n")); 
   
// Input character value 
// return its ASCII value 
var_dump(IntlChar::totitle(ord("D"))); 
var_dump(IntlChar::totitle(ord("d"))); 
   
// Input  ASCII value 0054 is "T" 
var_dump(IntlChar::totitle(ord("0054"))); 
var_dump(IntlChar::totitle(ord("@"))); 
   
?>

输出:

string(1) "G" 
string(1) "G" 
string(1) "A" 
string(2) " " 
string(1) " " 
NULL 
string(1) "9" 
string(1) " " 
int(68) 
int(68) 
int(48) 
int(64)

程序2:

<?php 
// PHP function to illustrate the 
// use of IntlChar::totitle() 
   
// Declare an array with 
// different codepoint value  
$arr = array("X", 
            "x",  
            "*", 
            "8", 
            "0", 
            " ",                
        ); 
     
// For loop condition to check  
// each character through function 
foreach ($arr as $val) { 
         
    // Check each element as code point data 
    var_dump(IntlChar::totitle($val)); 
} 
?>

输出:

string(1) "X"
string(1) "X"
string(1) "*"
string(1) "8"
string(1) "0"
string(1) " "

相关文章:

参考: http://php.net/manual/en/intlchar.totitle.php



相关用法


注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | IntlChar::totitle() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。