WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to find number of characters in a string in PHP

Topic: PHP / MySQLPrev|Next

Answer: Use the PHP strlen() function

You can use the PHP strlen() function to find the number of characters in a string of text. It also includes the white spaces inside the string.

  • <?php
  • $my_str1 = 'The quick brown fox jumps over the lazy dog.';
  • echo strlen($my_str1); // Outputs: 44
  •  
  • $my_str2 = '    The quick brown fox jumps over the lazy dog. ';
  • echo strlen($my_str2); // Outputs: 49
  • ?>

Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.