String length
This shows the string length of an input, using PHP strlen and mb_strlen
How to count a string's length
- Paste or type your text in the Input box.
- Press Submit.
- Read the three results: String length, MB string length and Encoding detected.
What the numbers mean
- String length is PHP's
strlen(): the number of bytes the text takes up in UTF-8. This is what a database column with a byte limit, a file size or a network protocol cares about. - MB string length is
mb_strlen(): the number of characters (Unicode code points). This is closer to what a person would count. - Encoding detected is
ASCIIwhen every character is plain English text, andUTF-8as soon as there's anything else.
Examples
| Text | Bytes | Characters | Encoding |
|---|---|---|---|
hello | 5 | 5 | ASCII |
héllo | 6 | 5 | UTF-8 |
日本語 | 9 | 3 | UTF-8 |
| 😀 | 4 | 1 | UTF-8 |
| 👍🏽 | 8 | 2 | UTF-8 |
Accented Latin letters take 2 bytes, most Asian scripts 3, and emoji 4. Some emoji are built from several code points, like the thumbs-up with a skin tone above, so even the character count can be higher than what you see.
Things that count
- Spaces, tabs and line breaks all count. A line break sent from a browser form is usually two characters (carriage return and line feed).
- Leading and trailing spaces are not trimmed.
FAQ
Why does my text fit a 280-character limit here but not on a website? Sites count differently: some count bytes, some count code points, and some count emoji or links as a fixed number. Check which one your target uses.
Why do the two numbers differ? Because some characters need more than one byte in UTF-8. If both numbers are the same, your text is plain ASCII.