php countchars,【函数分享】PHP函数count_chars 分享

这篇博客详细介绍了PHP的count_chars函数,它用于获取字符串中字符的使用情况。通过不同模式,可以获取到各个字符出现的次数或未使用的字节值。文章提供了实例代码,展示了如何使用此函数来统计字符串中各个字符的出现频率。
摘要由CSDN通过智能技术生成

每日分享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.

?>

关注是一种动力 分享是一种美德 关注分享一下又不会怀孕!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值