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

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



strlen(string $string)


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


$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.