• 首页
  • WindowsAPI
  • php
  • JavaScript
  • 字符串函数
    • 操作数组函数
      • 正则表达式函数
        • 文件或目录操作函数
          • 日期和时间函数
            • 数据库:Mssql函数函数
              • 解析XML函数
                • 数学计算进制转换函数
                  • 操作apache函数
                    • 其他
                      • 选项/信息函数
                        • 操作类或对象函数
                          • 判断检测变量函数
                            • 文件压缩:Bzip2函数
                              • cURL函数
                                • 数据库:IBM DB2 函数函数
                                  • 数据库:DBA函数
                                    • 数据库:dBase函数
                                      • 数据库:DB++函数
                                        • 数据库:dbx函数
                                          • 错误处理函数
                                            • 数据库:FrontBase函数
                                              • 数据库:filePro函数
                                                • 操作FTP函数
                                                  • 画图函数GD
                                                    • 文件压缩:Zlib函数
                                                      • 数据库:Firebird/InterBase函数
                                                        • 音频格式操作:ID3函数
                                                          • 数据库:Informix 函数函数
                                                            • 操作iis函数
                                                              • 音频格式操作:OpenAL函数
                                                                • 数据库:Ingres函数函数
                                                                  • KADM5函数
                                                                    • 文件压缩:LZF函数
                                                                      • 数据库:mSQL函数函数
                                                                        • 数据库:MySQL函数
                                                                          • 命令行扩展:Ncurses函数
                                                                            • 命令行扩展:Newt函数
                                                                              • 数据库:ODBC函数
                                                                                • OpenSSL函数
                                                                                  • 操作PDF函数
                                                                                    • 数据库:PostgreSQL函数
                                                                                      • 命令行扩展:Readline函数
                                                                                        • runkit函数
                                                                                          • Socket函数
                                                                                            • SSH2函数
                                                                                              • WinCache函数
                                                                                                • Xhprof函数
                                                                                                  • 文件压缩:Zip函数
                                                                                                    首页 > php > 字符串函数

                                                                                                    php:count_chars 用法

                                                                                                    函数结构

                                                                                                    函数名 返回值类型 描述
                                                                                                    count_chars mixed 返回字符串所用字符的信息
                                                                                                    参数名 数据类型 是否必须 备注
                                                                                                    $string string 必须 字符串
                                                                                                    $mode int 可空 默认值:0 整数型

                                                                                                    函数原型

                                                                                                    mixed count_chars ( string $string [, int $mode = 0 ] )

                                                                                                    统计 string 中每个字节值(0..255)出现的次数,使用多种模式返回结果。

                                                                                                    参数

                                                                                                    string

                                                                                                    需要统计的字符串。

                                                                                                    mode

                                                                                                    参见返回的值。

                                                                                                    返回值

                                                                                                    根据不同的 mode, count_chars() 返回下列不同的结果:

                                                                                                    • 0 - 以所有的每个字节值作为键名,出现次数作为值的数组。
                                                                                                    • 1 - 与 0 相同,但只列出出现次数大于零的字节值。
                                                                                                    • 2 - 与 0 相同,但只列出出现次数等于零的字节值。
                                                                                                    • 3 - 返回由所有使用了的字节值组成的字符串。
                                                                                                    • 4 - 返回由所有未使用的字节值组成的字符串。

                                                                                                    范例

                                                                                                    Example #1 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.\n" ;
                                                                                                    }
                                                                                                    ?>

                                                                                                    以上例程会输出:

                                                                                                    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.
                                                                                                    

                                                                                                    点击查看全部→[字符串函数]

                                                                                                    同类函数:

                                                                                                    函数名 函数简介
                                                                                                    addcslashes以 C 语言风格使用反斜线转义字符串中的字符
                                                                                                    addslashes使用反斜线引用字符串
                                                                                                    bin2hex函数把ASCII字符的字符串转换为十六进制值
                                                                                                    choprtrim 的别名
                                                                                                    chr返回指定的字符
                                                                                                    chunk_split将字符串分割成小块
                                                                                                    convert_cyr_string将字符由一种 Cyrillic 字符转换成另一种
                                                                                                    convert_uudecode解码一个 uuencode 编码的字符串
                                                                                                    convert_uuencode使用 uuencode 编码一个字符串
                                                                                                    count_chars返回字符串所用字符的信息
                                                                                                    crc32计算一个字符串的 crc32 多项式
                                                                                                    crypt单向字符串散列
                                                                                                    echo输出一个或多个字符串
                                                                                                    explode使用一个字符串分割另一个字符串
                                                                                                    fprintf将格式化后的字符串写入到流