count_chars

(PHP 4, PHP 5, PHP 7)

count_chars锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷息

说锟斤拷

count_chars ( string $string [, int $mode = 0 ] ) : mixed

统锟斤拷 string 锟斤拷每锟斤拷锟街斤拷值锟斤拷0..255锟斤拷锟斤拷锟街的达拷锟斤拷锟斤拷使锟矫讹拷锟斤拷模式锟斤拷锟截斤拷锟斤拷锟�

锟斤拷锟斤拷

string

锟斤拷要统锟狡碉拷锟街凤拷锟斤拷锟斤拷

mode

锟轿硷拷锟斤拷锟截碉拷值锟斤拷

锟斤拷锟斤拷值

锟斤拷锟捷诧拷同锟斤拷 mode锟斤拷count_chars() 锟斤拷锟斤拷锟斤拷锟叫诧拷同锟侥斤拷锟斤拷锟�

  • 0 - 锟斤拷锟斤拷锟叫碉拷每锟斤拷锟街斤拷值锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷锟街达拷锟斤拷锟斤拷为值锟斤拷锟斤拷锟介。
  • 1 - 锟斤拷 0 锟斤拷同锟斤拷锟斤拷只锟叫筹拷锟斤拷锟街达拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷纸锟街碉拷锟�
  • 2 - 锟斤拷 0 锟斤拷同锟斤拷锟斤拷只锟叫筹拷锟斤拷锟街达拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷纸锟街碉拷锟�
  • 3 - 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷使锟斤拷锟剿碉拷锟街斤拷值锟斤拷傻锟斤拷址锟斤拷锟斤拷锟�
  • 4 - 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷未使锟矫碉拷锟街斤拷值锟斤拷傻锟斤拷址锟斤拷锟斤拷锟�

锟斤拷锟斤拷

Example #1 count_chars() 示锟斤拷

<?php
$data 
"Two Ts and one F.";

foreach (
count_chars($data1) as $i => $val) {
   echo 
"There were $val instance(s) of \"" chr($i) , "\" in the string.\n";
}
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

There were 4 instance(s) of " " in the string.
There were 1 instance(s) of "." in the string.
There were 1 instance(s) of "F" in the string.
There were 2 instance(s) of "T" in the string.
There were 1 instance(s) of "a" in the string.
There were 1 instance(s) of "d" in the string.
There were 1 instance(s) of "e" in the string.
There were 2 instance(s) of "n" in the string.
There were 2 instance(s) of "o" in the string.
There were 1 instance(s) of "s" in the string.
There were 1 instance(s) of "w" in the string.

锟轿硷拷

  • strpos() - 锟斤拷锟斤拷锟街凤拷锟斤拷锟阶次筹拷锟街碉拷位锟斤拷
  • substr_count() - 锟斤拷锟斤拷锟街达拷锟斤拷锟街的达拷锟斤拷