strlen
Returns the length of a string in bytes.
Available since: PHP 4
Syntax
strlen(string $string): intParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The string to measure. |
Return value
intThe number of bytes in the string; 0 for an empty string.
Examples
Length of an ASCII string:
<?php
echo strlen('hello');Output:
5A Cyrillic letter takes two bytes in UTF-8, so the result is twice the number of letters:
<?php
echo strlen('привет'), "\n";
echo mb_strlen('привет');Output:
12
6Notes
The function counts bytes, not characters. To get the number of characters in non-ASCII text, use mb_strlen().
See also
- mb_strlen — Returns the number of characters in a string.
Related recipes
In the tutorial
- Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.