How to find string length in PHP

Topic: PHP / MySQL« Prev|Next »

Answer: Use the PHP strlen() function

You can use the PHP strlen() to get the length of a string. The strlen() function return the length of the string on success, and 0 if the string is empty.

  • <?php
  • $str1 = 'Hello world!';
  • echo strlen($str1); // Outputs: 12
  • echo "<br>";
  •  
  • $str2 = ' Hello    world! ';
  • echo strlen($str2); // Outputs: 17
  • ?>

Related FAQ

Here are some more FAQ related to this topic:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.