Skip to tool

PHP count_chars() Online

Count frequency of characters/code points.

The output updates as you type. The tool processes input in your browser.

Worked example

The result counts occurrences of each Unicode code point. A grapheme may span several entries. Native PHP count_chars() counts bytes, so UTF-8 text can produce different results.

Sample input
banana
Sample output
[
  {
    "codepoint": 97,
    "char": "a",
    "count": 3
  },
  {
    "codepoint": 98,
    "char": "b",
    "count": 1
  },
  {
    "codepoint": 110,
    "char": "n",
    "count": 2
  }
]

Using this operation in PHP

The interactive result uses JavaScript. PHP strings hold bytes. Use the multibyte string extension when offsets or lengths should follow decoded characters.

PHP reference