Count Words in a String: Write a PHP function to count the number of words in a given string.

function countWords($str) {
    return str_word_count($str);
}

// Example usage:
$string = "The quick brown fox jumps over the lazy dog";
echo "Word count: " . countWords($string);

Related Posts

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Artificial Intelligence