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.
Related Tutorials
PHP explode() – split a string by string into array
PHP explode() function is used for split a string by another string into an array.This function is used when we...
PHP trim() – Remove whitespace from string
PHP trim() function is used for removing the white space or other characters from starting and end of a string....
call function in PHP
We can create our own function inside our PHP programs for re-usability and making our code optimization purposes. Functions are...
PHP wordwrap function
PHP wordwrap() function is used for wrapping a string to a given number of characters. It will cut the string...
strpos() – PHP string first occurance position
PHP strpos function is using for checking the occurrence position of a character or string within a string.It will return...
Split a string and store into an array
This PHP script code is for split a string into the specified length and store it into an array. Here...
PHP $_GET function with forms
PHP $_GET function is sued for collection the values passed from a “form using get method”.There are two types of...
PHP $_POST function with forms
PHP $_POST function is sued for collection the values passed from a “form using post method”.There are two types of...
For easy to remember strlen function … Use “String length” …. “str” from string and “len” from Length