Word Cutter function in PHP

PHP Frameworks

In WordPress, it is very popular to show excerpt of a content which shows up to particular word limits.

In each and every cases it is not require to show the whole content rather than small content with limited words.

Below function is an example of word limit or word cutter for a content.

function wordCutter($str,$len) {
  $str = substr(strip_tags(html_entity_decode($str)),0,len);
  $pos   = strrpos($str," ");
  $str = substr(strip_tags(html_entity_decode($str)),0,$pos).'...';
  $str = strip_tags(html_entity_decode($str));

Leave a Reply

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