Infolinks

Breaking

Adsense

Thursday, April 28, 2016

HOW TO COUNT WORDS IN A SENTENCE USING PHP


Hi there buddy!  I am back and bringing with me another nice article for you to learn on. This time I am going to share a simple word count program using PHP’s basic function which is the str_word_count() function. Makes your life easier with just a simple function.
So here is the code for you to understand well.

PHP CODE FOR WORD COUNT

<?php
$string="Hello world! I am back!";
echo str_word_count($string);
?>

The code above will count all the words from the string value “Hello world! I am back!”. The str_word_count() function will count words separated by a space. So the code above will display an output of five (5).


echoor print  is used to display an output to the user. Hope you learn something from this article! Keep coming back on my blog for more interesting and informative post from me.

HOW TO COUNT WORDS IN A SENTENCE USING PHP

No comments:

Post a Comment

Adbox