string-length tagged requests and articles

Categorized request examples and articles tagged with [string-length] keyword
How can I get the length of a string in PHP?
To get the length of a string in PHP, use the strlen($string) built-in function. The strlen() takes a string as an argument and returns the length of the string. The strlen() function returns the number of bytes, not characters. If your string contains Unicode characters, strlen() will return a string length bigger than the number of visible characters since Unicode characters are represented in PHP as 2 bytes. 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. Multiple strlen() calls for long PHP strings are almost as fast as a single call. In this PHP String Length example, we use the strlen() function to get the length of an ASCII string (without Unicode characters). Click Execute to run the PHP String Length example online and see the result.