Your destination for complete Tech news

PHP

How to find the length of string in PHP?

22 0
< 1 min read

To find the length of a string in PHP, you can use the strlen() function. This function returns the number of characters in the string.

For example:

$string = 'Hello';
$length = strlen($string);

// $length will be equal to 5

You can also use the mb_strlen() function to find the length of a string in bytes, or to count the number of characters in a multibyte string. This function requires the mbstring extension to be enabled in your PHP configuration.

For example:

$string = 'Hello';
$length = mb_strlen($string, 'UTF-8');

// $length will be equal to 5

Leave A Reply

Your email address will not be published.

20 − twelve =

This site uses Akismet to reduce spam. Learn how your comment data is processed.