WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES
Advertisements

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

Topic: PHP / MySQLPrev|Next

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);
?>

Related FAQ

Here are some more FAQ related to this topic:

Advertisements
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties