<?php function countwordscustom($string, $limit) { $str_code = explode(" ",$string); return implode("",array_splice($str_code,0,$limit)); } ?>
If you want to use this function anywhere in your PHP file follow given example
<?php $text = "EWA is a very good website the design of the website is very cool and good looking."; echo countwords($text,7); ?>
It will display only 7 words “EWA is a very good website the” and your word will never break.
Thanks and Enjoy the Coding.