How to find the number of words in a string in PHP?

How to find the number of words in a string in PHP?

 

Asked on November 1, 2018 in PHP.
Add Comment


  • 1 Answer(s)

    PHP str_word_count() function is used.

    The PHP str_word_count() function is used to find the number of words in a string.

    For example:

    <?php
    $my_str = 'The quick brown fox jumps over the lazy dog.';
     
    // Outputs: 9
    echo str_word_count($my_str);
    ?>
    
    Answered on November 1, 2018.
    Add Comment


  • Your Answer

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