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.

Output

23

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.

Output

17

Reference
PHP net Doc

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.