strlen
(PHP 4, PHP 5, PHP 7, PHP 8)
strlen — Get string length
Description
$string
): int
Returns the length of the given string
.
Parameters
-
string
-
The string being measured for length.
Return Values
The length of the string
on success,
and 0
if the string
is empty.
Examples
Example #1 A strlen() example
<?php
$str = 'abcdef';
echo strlen($str); // 6
$str = ' ab cd ';
echo strlen($str); // 7
?>
Notes
Note:
strlen() returns the number of bytes rather than the number of characters in a string.
Note:
strlen() returns
null
when executed on arrays, and anE_WARNING
level error is emitted.
See Also
- count() - Counts all elements in an array or in a Countable object
- grapheme_strlen() - Get string length in grapheme units
- iconv_strlen() - Returns the character count of string
- mb_strlen() - Get string length