首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

【函数分享】PHP函数count_chars 分享

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

?>

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

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20200927A013CK00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券