In this tutorial, you shall learn how to get the length of a string in PHP using strlen() function, with examples.

PHP String Length

To get the length of a string in PHP, you can use strlen() function. Pass the string as argument to strlen() and the function returns an integer representing the length of string.

Example

In the following example, we will take a PHP String literal and find its length using strlen() function.

PHP Program

<?php
$str = 'Welcome to TutorialKart';
$length = strlen($str);
echo $length;
?>

Program Output

PHP String Length
ADVERTISEMENT

Conclusion

In this PHP Tutorial, we learned how to find the length of a string using strlen() function.