count_chars — 返回字符串所用字符的信息
count_chars函数基本语法
count_chars(string,mode)
统计 string 中每个字节值(0..255)出现的次数,使用多种模式返回结果。
count_chars参数介绍
| 参数 | 描述 |
|---|---|
| string | 必需。需要统计的字符串。 |
| mode |
可选。规定返回模式。默认是 0。以下是不同的返回模式:
|
count_chars返回值
根据不同的 mode, count_chars() 返回下列不同的结果:
- 0 - 以所有的每个字节值作为键名,出现次数作为值的数组。
- 1 - 与 0 相同,但只列出出现次数大于零的字节值。
- 2 - 与 0 相同,但只列出出现次数等于零的字节值。
- 3 - 返回由所有使用了的字节值组成的字符串。
- 4 - 返回由所有未使用的字节值组成的字符串。
count_chars实例
<?php
$data = \"Two Ts and one F.\" ;
foreach ( count_chars ( $data , 1 ) as $i => $val ) {
echo \"There were $val instance(s) of \\\"\" , chr ( $i ) , \"\\\" in the string.<br/>\" ;
}
?>
运行结果:
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.
继续阅读与本文标签相同的文章
上一篇 :
2019 年可以选用这些 Rust IDE/DE
下一篇 :
2020 时代的开发人员关键词:开源和远程办公
-
未来十年,最为吃香的4个大学专业,毕业后就是香饽饽!
2026-05-14栏目: 教程
-
还不会制作填充地图,试试这种方法,2分钟搞定,让你秒变大神
2026-05-14栏目: 教程
-
顺丰自研机器人惊艳亮相,化身“快递小哥”亮绝活,盯上万亿市场
2026-05-14栏目: 教程
-
女生“主动”与你分享这3个秘密?520%偷偷喜欢你,臭弟弟冲鸭
2026-05-14栏目: 教程
-
这4类大学专业很吃香,市场人才紧缺,毕业后前景很好!
2026-05-14栏目: 教程
