How to find number of characters in a string in PHP?

How to find number of characters in a string in PHP?

Asked on November 1, 2018 in PHP.
Add Comment


  • 1 Answer(s)

    This can be done by using PHP strlen() function.
    The PHP strlen() function is used to find the number of characters in a string of text. It also includes the white spaces inside the string.

    For example:

    <?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
    ?>
    
    Answered on November 1, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.