How can I find the length of a string in PHP?

To get the length of a string in PHP, use the strlen() built-in function. The strlen() takes a string as its first argument and returns the length of the string. The strlen() function returns the number of bytes, not characters, in a string. If your string contains Unicode characters, which are represented as 2 bytes in PHP, then strlen() will return the number of bytes that will be greater than the number of visible characters. To get the number of visible characters, use the mb_strlen($string, 'utf8') function instead of strlen(). Recent versions of PHP have significantly improved the performance of the strlen() function. Now multiple strlen() calls for very long PHP strings are almost as fast as a single call. In this PHP String Length Example, we are using the strlen() function to calculate and print the length of the string. Click Execute, to run the PHP strlen() example online and see the result.
How can I find the length of a string in PHP? Execute
echo strlen("Hello World!");
Updated: Viewed: 1826 times