strlen(): PHP String length
Output is the length of the string in number of bytes.
This function is required for form input validation. We can check if any input field is entered blank.
PHP function strlen returns number of bytes inside the string including blank space. If you want blank space to be removed then you can apply string replace function str_replace to the string before applying strlen.
The output of above code is 17
Length of the string after removing blank spacesWe will use str_replace function to search and replace all occurrences of blank space.
The output of above code is 14
Maximum and minium length of stringWhile checking the userid of signup script we can use this to findout the length of the string. Here our string should be of minimum 6 and maximum 15 character length.
Null variable and strlen()
Checking null variable by using strlen() may not give desire result.
strlen() returns number of bytes rather than number of characters.
This article is written by plus2net.com team.