php count_chars() 函数
实例
返回一个字符串,包含所有在 "hello world!" 中使用过的不同字符(模式 3):
<?php $str = "hello world!"; echo count_chars($str,3); ?>
定义和用法
count_chars()
函数返回字符串所用字符的信息(例如,ascii 字符在字符串中出现的次数,或者某个字符是否已经在字符串中使用过)。
语法
count_chars( _string,mode_ )
实例 1
返回一个字符串,包含所有在 "hello world!" 中未使用过的字符(模式 4):
<?php $str = "hello world!"; echo count_chars($str,4); ?>
实例 2
在本实例中,我们将使用 count_chars() 来检查字符串,返回模式设置为 1。模式 1 将返回一个数组,ascii 值为键名,出现的次数为键值:
<?php $str = "hello world!"; print_r(count_chars($str,1)); ?>
实例 3
统计 ascii 字符在字符串中出现的次数另一个实例:
<?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>"; } ?>
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对移动技术网的支持。如果你想了解更多相关内容请查看下面相关链接
如对本文有疑问, 点击进行留言回复!!
php 使用 yansongda/pay 进行微信,支付宝支付
Codeforces Round #658 (Div. 2) (C1、C2)
van-uploader + thinkphp6.0 图片上传
网友评论