Kathmandu,Nepal
Kathmandu,Nepal

Count the number of words in a string in PHP

To counts the number of words in a string,we use PHP function i.e. str_word_count().

The str_word_count() method is used to counts the number of words in a string.

<?php
$string = "Web design and development";
$words = str_word_count($string);
echo $words;
?>
Output:
4

Leave a Comment

Your email address will not be published. Required fields are marked *

×