php count_chars() function
Translation results:
UK[tʃa:z] US[tʃa:z]
abbr.characters (plural) roles, characters (terms used in scripts)
v. Burn... into charcoal, burn ...charred (third person singular of char); burnt into charcoal, charred; <Master Ying> working as a handyman maid
php count_chars() functionsyntax
Function:Returns a string containing all the different characters used in the string
Syntax: count_chars(string,mode)
Parameters:
Parameter | Description |
string | Required. Specifies the string to check. |
mode | Optional. Specifies the return mode. The default is 0. The following are the different return modes: 0 - array, ASCII value as key name, the number of occurrences as key value, 1 - array, ASCII value as key name, the number of occurrences as key value, only values with occurrences greater than 0 are listed , 2 - array, ASCII value is the key name, the number of occurrences is the key value, only values with the number of occurrences equal to 0 are listed, 3 - string, with all different characters used, 4 - string, with All unused different characters |
Description: Returns information about the characters used in the string
php count_chars() functionexample
<?php //使用模式3输出 $str = "Hello php.cn!"; echo count_chars($str,3); ?>
Run instance»
Click the "Run instance" button to view the online instance
Output:
!.Hcehlnop
<?php //使用模式1的数组形式输出 $str = "Hello php.cn!"; print_r(count_chars($str,1)) ; ?>
Run Instance»
Click the "Run Instance" button to view the online instance
Output:
Array ( [32] => 1 [33] => 1 [46] => 1 [72] => 1 [99] => 1 [101] => 1 [104] => 1 [108] => 2 [110] => 1 [111] => 1 [112] => 2 )