To find string length you can use the PHP strlen function. Pass the string variable as the argument of the
strlen() to get the length of the string.
Example to Find String Length With strlen()
Many developers use the
strlen() to Find String Length and show the minimal string using the PHP echo statement. A sentence of the string contains single space among each word. The function also considers and add the space as the string length.
$string1 = "This is myfirst string.";
The above example contains a single string which is stored in s string variable. The string length printed here by passing the string variable in the strlen().
Example to Get String Length With More than one Space
If the sentence contains extra space with the words, the
strlen() also add all the space as the string length.
The below example contains the 5 space between the string words and there are 12 characters in the string.
$string2 = "Second string";
PHP net Doc