strlen()

strlen() — Get string length.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

strlen(string $string): int

Parameters

ParameterTypeWhat it takes
$stringstringThe string being measured for length.

Return value

The length of the string in bytes.

Example

A runnable snippet:

$str = 'abcdef'; echo strlen($str), PHP_EOL; // 6 $str = ' ab cd '; echo strlen($str), PHP_EOL; // 7

See also

count(), iconv_strlen(), mb_strlen()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page strlen() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.