Word Cutter function in PHP

array_map

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) {
 if(strlen(strip_tags(html_entity_decode($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).'...';
 }
 else
 {
  $str = strip_tags(html_entity_decode($str));
 }
}

For any types of queries, you can contact us on info@namasteui.com.

Leave a Reply

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