PHP count_chars() 函數(shù)
定義和用法
count_chars() 函數(shù)返回字符串所用字符的信息。
語法
count_chars(string,mode)
參數(shù) | 描述 |
---|---|
string | 必需。規(guī)定要檢查的字符串。 |
mode |
可選。規(guī)定返回模式。默認(rèn)是 0。有以下不同的返回模式:
|
實例
例子 1
在本例中,我們將使用 count_chars() 來檢查字符串,返回模式設(shè)置為 1:
<?php
$str = "Hello World!";
print_r(count_chars($str,1)
);
?>
輸出:
Array ( [32] => 1 [33] => 1 [72] => 1 [87] => 1 [100] => 1 [101] => 1 [108] => 3 [111] => 2 [114] => 1 )
例子 2
在本例中,我們將使用 count_chars() 來檢查字符串,返回模式設(shè)置為 3:
<?php
$str = "Hello World!";
echo count_chars($str,3)
;
?>
輸出:
!HWdelor