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.




  • string (Required) - Specifies the string to check


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

$str = ' ab xyz ';
echo strlen($str); // 8

Actually, 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.

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive