How to Find String Length in PHP - strlen() Function

PHP String Functions

The strlen() function returns the length of a given string. It returns 0 if the string is empty.

images/articles/php/find-string-length-in-php-strlen.jpg

Syntax

strlen(string $string)

Parameter

  1. string (Required) - Specifies the string to check

Example

$str = 'abcdef';
echo strlen($str);

The output of the above example will be 6.

The function strlen() returns the number of bytes rather than the number of characters in a string. So, if there are characters that take more than 1 byte, you may not get the actual length.