每日分享PHP知识点,大家都赞同关注是一种动力,分享是一种美德,再说了关注分享一下又不会怀孕?只要你开心就好......
count_chars () 返回字符串所用字符的信息。
mixed count_chars(string$string[,int$mode=])
说明:
统计 string 中每个字节值(0..255)出现的次数,使用多种模式返回结果。
参数描述
string
需要统计的字符串。
mode
参见返回的值。
返回值:
根据不同的 mode,count_chars() 返回下列不同的结果:
◦ 0 - 以所有的每个字节值作为键名,出现次数作为值的数组。
◦ 1 - 与 0 相同,但只列出出现次数大于零的字节值。
◦ 2 - 与 0 相同,但只列出出现次数等于零的字节值。
◦ 3 - 返回由所有使用了的字节值组成的字符串。
◦ 4 - 返回由所有未使用的字节值组成的字符串。
实例:
$data="Two Ts and one F.";
foreach(count_chars($data,1)as$i=>$val){ echo"There were$valinstance(s) of \"",chr($i),"\" in the string.\n";
}
//输出
There were4instance(s)of" "in the string.
There were1instance(s)of"."in the string.
There were1instance(s)of"F"in the string.
There were2instance(s)of"T"in the string.
There were1instance(s)of"a"in the string.
There were1instance(s)of"d"in the string.
There were1instance(s)of"e"in the string.
There were2instance(s)of"n"in the string.
There were2instance(s)of"o"in the string.
There were1instance(s)of"s"in the string.
There were1instance(s)of"w"in the string.
?>
关注是一种动力 分享是一种美德 关注分享一下又不会怀孕!
领取专属 10元无门槛券
私享最新 技术干货