php count_chars 返回字符串所用字符的信息
时间:2016-01-28
php count_chars函数统计 string 中每个字节值(0..255)出现的次数,使用多种模式返回结果。 本文章向大家介绍php count_chars 函数的基本语法以及使用实例,需要的码农可以参考一下。
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.
- (44) 剖析TreeSet / 计算机程序的思维逻辑
- (46) 剖析PriorityQueue / 计算机程序的思维逻辑
- (48) 剖析ArrayDeque / 计算机程序的思维逻辑
- 那些年在win下填过的Django坑
- Python爬虫一步步抓取房产信息
- (47) 堆和PriorityQueue的应用 / 计算机程序的思维逻辑
- 一篇文章完全理解virtualenv
- Python运用蒙特卡洛算法模拟植物生长
- (57) 二进制文件和字节流 / 计算机程序的思维逻辑
- 真正的 Tornado 异步非阻塞
- (58) 文本文件和字符流 / 计算机程序的思维逻辑
- Python爬虫—破解JS加密的Cookie
- Python通过抓包和使用cookie爬取微博完全讲解
- (50) 剖析EnumMap / 计算机程序的思维逻辑
- php概述
- php教程
- php环境搭建
- PHP书写格式
- php变量
- php常量
- PHP注释
- php数组
- php字符串 string
- PHP整型 integer
- PHP浮点型 float
- php布尔型
- php数据类型之数组
- php数据类型之对象
- php数据类型之null
- php数据类型之间的转换
- php运算符
- php表达式
- PHP循环控制
- PHP流程控制
- php函数
- php全局变量
- PHP魔术变量
- php命名空间
- php 日期
- PHP包含文件
- php文件
- PHP 文件上传
- php Cookies
- php Sessions
- php email
- php安全email
- php错误处理
- PHP异常处理
- php过滤器
- PHP 高级过滤器
- php json
- php 表单
- PHP MySQL 简介
- PHP 连接 MySQL
- php创建数据库
- php 创建表
- php mysq 插入数据
- PHP MySQL 插入多条数据
- PHP MySQL 预处理语句
- php mysql 读取数据
- php mysql where
- PHP MySQL Order By
- PHP MySQL Update
- PHP MySQL Delete
- php ODBC
- 【DB笔试面试862】在Oracle中,如何安装DBMS_NETWORK_ACL_ADMIN包?
- 【DB宝19】在Docker中使用MySQL高可用之MHA
- 【DB笔试面试863】在Oracle中,如何让Oracle DB、监听和oem开机启动?
- 【DB笔试面试864】在Oracle中,响应文件在什么位置?
- 设计模式几大原则
- Thrift使用教程(Java版本)
- C语言实现三子棋
- C语言操作符
- 一级指针、二级指针、指针和数组、指针数组总结
- C++入门知识(一)
- C++入门知识(二)
- 容易混淆的const
- MySQL数据库学习笔记之数据库及SQL/MySQL基础
- 时间复杂度与空间复杂度总结
- 顺序表总结以及代码实现