小白教程
所有教程
关于
Search
172.70.126.178
172.70.126.178
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Func string count chars”的源代码
本页内容
上一节:
Func_string_convert_uuencode
下一节:
Func_string_crc32
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:count_chars()}}[[分类:PHP字符串函数参考手册|10]] = PHP count_chars() 函数 = [[:分类:PHP字符串函数参考手册]] 返回一个字符串,包含所有在 "Hello World!" 中使用过的不同字符(模式 3): <sample title="" desc="" lang="php" hererun="1"> <?php $str = "Hello World!"; echo count_chars($str,3); ?> </sample> == 定义和用法 == count_chars() 函数返回字符串所用字符的信息(例如,ASCII 字符在字符串中出现的次数,或者某个字符是否已经在字符串中使用过)。 == 语法 == <pre> count_chars(string,mode) </pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | string | 必需。规定要检查的字符串。 |- | mode | 可选。规定返回模式。默认是 0。有以下不同的返回模式: * 0 - 数组,ASCII 值为键名,出现的次数为键值 * 1 - 数组,ASCII 值为键名,出现的次数为键值,只列出出现次数大于 0 的值 * 2 - 数组,ASCII 值为键名,出现的次数为键值,只列出出现次数等于 0 的值 * 3 - 字符串,带有所有使用过的不同的字符 * 4 - 字符串,带有所有未使用过的不同的字符 |} == 技术细节 == {| class="table table-striped table-hover" | 返回值: | 取决于指定的 mode 参数。 |- | PHP 版本: | 4+ |} == 更多实例 == == 实例 1 == 返回一个字符串,包含所有在 "Hello World!" 中未使用过的字符(模式 4): <sample title="" desc="" lang="php" hererun="1"> <?php $str = "Hello World!"; echo count_chars($str,4); ?> </sample> == 实例 2 == 在本实例中,我们将使用 count_chars() 来检查字符串,返回模式设置为 1。模式 1 将返回一个数组,ASCII 值为键名,出现的次数为键值: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "Hello World!"; print_r(count_chars($str,1)); ?> </sample> == 实例 3 == 统计 ASCII 字符在字符串中出现的次数另一个实例: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "PHP is pretty fun!!"; $strArray = count_chars($str,1); foreach ($strArray as $key=>$value) { echo "The character <b>'".chr($key)."'</b> was found $value time(s)<br>"; } ?> </sample> [[:分类:PHP字符串函数参考手册]]
返回至“
Func string count chars
”。
上一节:
Func_string_convert_uuencode
下一节:
Func_string_crc32