Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the PHP str_word_count() function

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

Let's check out an example to understand how this function basically works:

<?php
$my_str = 'The quick brown fox jumps over the lazy dog.';
 
// Outputs: 9
echo str_word_count($my_str);
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now