strlen() – PHP string length function

While our PHP programming , in some cases we need to get the length of a string for processing. strlen() if the function in PHP to get the length of a string.

See the sample program with strlen() function:

<?php
$variable="Check length";
echo strlen($variable);
?>

It will output the result

12

strlen function will count the blank spaces also contains in the string.

For looping through a string, we can use this function to know the end of loop by storing the length of string to a variable. And in other cases we can use this function for data checking like password length and all.

It will return 0 ( zero ) if the string is empty.

Share

One thought on “strlen() – PHP string length function”

  1. For easy to remember strlen function … Use “String length” …. “str” from string and “len” from Length

Comments are closed.

Share
Share