php

How to count number of words in a string in PHP

In this tutorial, we are going to see how to count number of words in a string in PHP. str_word_count() function in PHP can be used to find the number of words in a string. See the example below:
 

How to count number of words in a string in PHP
<?php
	$str = 'Welcom to StackHowTo.';

	echo str_word_count($str); 
?>

Output:

3
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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