Easy Tutorial
❮ Php Preg_Replace Func String Str Shuffle ❯

PHP count_chars() Function

PHP String Reference Manual

Example

Returns a string containing all unique characters used in "Hello World!" (mode 3):


Definition and Usage

The count_chars() function returns information about characters used in a string (e.g., the number of times an ASCII character appears in the string, or whether a character has been used in the string).


Syntax

Parameter Description
string Required. Specifies the string to be checked.
mode Optional. Specifies the return mode. Default is 0. The following return modes are available: 0 - Array with ASCII values as keys and their frequency as values<br> 1 - Array with ASCII values as keys and their frequency as values, only listing frequencies greater than 0<br> 2 - Array with ASCII values as keys and their frequency as values, only listing frequencies equal to 0<br> 3 - String containing all unique characters used<br> 4 - String containing all unique characters not used

Technical Details

Return Value: Depends on the specified mode parameter.
PHP Version: 4+
--- ---

More Examples

Example 1

Returns a string containing all characters not used in "Hello World!" (mode 4):

Example 2

In this example, we will use count_chars() to check a string, with the return mode set to 1. Mode 1 will return an array with ASCII values as keys and their frequency as values:

Example 3

Another example of counting the frequency of ASCII characters in a string:

❮ Php Preg_Replace Func String Str Shuffle ❯