PHP count_chars() Function

Definition

The count_chars() function returns an array containing the letters used in that string and how many times each letter was used.

Syntax

PHP count_chars() function has the following syntax.

mixed count_chars ( string str [, int mode] )

Parameter

If the mode parameter is 1, only letters with a frequency greater than 0 are listed; if the mode parameter is 2, only letters with a frequency equal to 0 are listed.

Return

PHP count_chars() function returns the character count.

Example

Get the caracter count


<?PHP//from w ww.  jav a  2  s .  c o  m
$str = "This is a test from java2s.com."; 
$a = count_chars($str, 1); 
print_r($a); 
?>

In that output, ASCII codes are used for the array keys, and the frequencies of each letter are used as the array values.

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions